DownloadManager set title change my filename

I used DownloadManager in my application to download a file from the internet. Here is my code.

DownloadManager downloadManager = (DownloadManager) ui.activity.getSystemService(Activity.DOWNLOAD_SERVICE);
Uri Download_Uri = Uri.parse("http://dl.appvn.com/appvn.apk");
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);


request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
                  .
request.setAllowedOverRoaming(false);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"appvn.apk");

request.setTitle("AppStoreVN");

request.setDescription("Android Data download using DownloadManager.");

downloadManager.enqueue(request);

      

I used setTitle and setDescription to change the display of information in the notification bar. But this also changes my filename to be title ("AppStoreVN" while it should be "appvn.apk"). Does anyone have any idea? Thanks to

+3


source to share


3 answers


I came here finding that what I thought was the same problem that when I look in the Download app on my phone I see the file header instead of .apk

I found that if I use a file explorer even though the actual filename is correct, it just the download app shows the details of the content database and should set the title the same as the title of the notification.



If it won't parse the file, take a look at the logcat as the file location was not generated as I expected.

0


source


to get the name of the download file I used:

String nameOfFile = URLUtil.guessFileName(mDownloadFileUrl, null,
                MimeTypeMap.getFileExtensionFromUrl(mDownloadFileUrl));

      

then to set the title and description of DownloadManager

request.setDescription(nameOfFile);
request.setTitle(nameOfFile);

      



Then to set the actual filename of the downloaded file in the directory path

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
 /*here the name of file is set*/nameOfFile);

      

hope this helps you :)

0


source


you can set the Destination as shown below where you can also specify the filename.

setDestinationUri() 

      

or

setDestinationInExternalPublicDir("/mnt/sdcard/", "test.jpg");

      

-1


source







All Articles