DownloadManager not adding the file extension - android

I would like to download from my server *.apk file, the file type on the server is *.apk and the MIME is application/vnd.android.package-archive",
when downloading with the DownloadManager the file is downloaded but it creating it without the extension "apk", I tried this
request.setMimeType("application/vnd.android.package-archive");
and still no luck the file created without the extension,
when trying to download it with Chrome it worked perfectly...
please help.

I thought request.setMimeType(..) is used it will add the file extension automatically or Android will recognize the file type,but no... you need to use setDestinationInExternalPublicDir(...)
and set the file extension here....

Related

File doesn't exist using Download Manager

According to this answer it's possible to copy a local file to the download older.
After trying this out:
DownloadManager downloadManager = (DownloadManager)getContext().getSystemService(getActivity().DOWNLOAD_SERVICE);
if(f.exists()){
downloadManager.addCompletedDownload("title", "descirption", true, "application/json", f.getPath(),f.length(),true);
}
I receive the following issue:
java.lang.IllegalArgumentException: File doesn't exist: /data/data/com.example.mytestapp/files/fd92a63b-aad5-4122-a23a-743d164243a1.jpg
Did this feature got cancelled in the newest android versions (30-31) and I have to copy the file in another way or is something wrong with my implementation.

Cannot copying file from Android to Linuxmint 17.3 Desktop "libmtp error: Could not get file from device"

I am trying to copy image file to backup it on my desktop which is linux mint (17.3 or Rosa) installed. I am using Infinix X510 phone with the newest version of android 6. At the beginning it was OK. But, at the end i get the message
“libmtp error: Could not get file from device”
I tried the solution as found by Googling here https://askubuntu.com/questions/879029/libmtp-error-could-not-get-file-from-device-on-attempting-to-transfer-files
But, it wasn't working for me. Is there a way to solve this matter? I need file to support my company job which supplying cosmetics.
Try compressing the file to a compressed format(tar,zip).Copy the file and then decompress it.
Changing the filename was the solution for me e.g: file.mkv to file.zip
Try to rename file, make sure file name not contain (-) (:) etc. Just rename it to alphabet

Put an existing file to data\data\app_name\files during .apk installaion

I need to work with a file,that should be at data\data\app_name\files\ . That is now an SQL Database, so solution with SQLiteOpenHelper isn't ok for me. Also, I copyied that file to app_name\app\assets in my profect folder - that didn't work.
How to add that file to installation .apk, to put it in data\data\app_name\files during the installation?
Save your file in \res\raw within your project.
Then, you can access that file using:
InputStream databaseInputStream = getResources().openRawResource(R.raw.yourfile);
Make sure that the resource files are included correctly when generating the apk.

downloading android .apk as .zip in android issue

I have developed an application,but when my client tries to download the application from the url provided using Samsung GT19003,it is downloading as .zip file and on click of that it says could not open the file error.Whereas it downloads as .apk and works good in our devices.Please help me as how can i resolve the issue.
Make sure that you have set the http Content-Type to application/vnd.android.package-archive
This let the chrome know that it is an application not a zip.
A simple solution is to add the below line in /etc/mime.types
application/vnd.android.package-archive apk
And restart your apache.
This will force browsers to download files as "apk" and not append "zip" to it.
if its being downloaded as .zip
You or your client can use File Expert application to unzip this .zip file it must show .apk file in the unzip folder
give a direct apk link to your user either he/she use default browser to download or use some other like opera and if it is .apk file link then it must be downloaded as is.
you may be using some content site which zip file on particular download methods please ensure it for direct .apk link.
EDIT 1:
Last but not the least .apk is just a zip file so this is not an issue just rename it(From .Zip to .apk) if you could and i hope it will solve the problem
In my case also the issue was same as #alireza-fattahi mentioned regarding the header.
Sharing this here because in our case the file was in Azure Storage and accessed by a CDN in case anyone has the same issue.
Fix for Azure Sorage and CDN
By default the APK blob that was uploaded had content type of application/zip and the same content type reflected in the reposnse header causing the downloaded file to get a .zip extension on Android OS when download was finished.
I had to set a custom rule in the storage CDN to overwrite content-type header in the response to application/vnd.android.package-archive
Remember to purge the CDN cache after you set the new rule
Read more about Azure CDN rules engine.
Here is the Example :
// set your download apk path here
$path= public_path(). "/upload/apk/Ninja11.apk";
//Set header here like this
$headers = [
'Content-Type'=>'application/vnd.android.package-archive',
'Content-Disposition'=> 'attachment; filename="ninja-release.apk"',
];
return response()->file($path , $headers);
This is Laravel framework code but in the same way, you can use in other frameworks. Simply you need to set the Content type
Note : This is not Android side issues

Adobe Air for Android: Where is a xml file after instalation .apk file

An Air app which loading data from an external XML file (cfg.xml). I've published the Android/Air file, included the cfg.xml file in the Android package. Then I've installed on my SD Card(). App's reading xml file - working perfectly. But I need raw access(on my device) to cfg.xml I cannot find this file, checked everywhere(Rooted Phone). Where is it? Is there other solution? I need a file which is easy to read/write.
Use DDMS -> File Explorer and look for you app name in folders like data, ...
Solution:
Use fileStream instead of URLLoader
Change directory to SD Card e.g.
File.userDirectory.resolvePath("YourAppData/cfg.xml")
(No rooted phone needed)

Categories

Resources