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
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With