Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DownloadManager set title change my filename

I used DownloadManager in my application to download file from internet. Here's 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 & setDescription to change the info show on Notification bar. But it also change my file name like title ("AppStoreVN" while it should be "appvn.apk"). Anyone have ideas? Thanks

like image 204
tuan.giao Avatar asked Nov 23 '22 08:11

tuan.giao


1 Answers

for getting name of downloading file i used:

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

then for setting title and description of DownloadManager

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

Then for setting actual file name of downloaded file in directory path

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

hope this help you :)

like image 187
LEGEND MORTAL Avatar answered Nov 24 '22 22:11

LEGEND MORTAL