Created
October 25, 2019 07:33
-
-
Save anilkumar416/a0b6236bffb6c974aed69f63d70f630c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//file download after permission check | |
private void fileDownload(String url, String fileName, String fileExtension) { | |
fileName = fileName + "." + fileExtension; | |
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); | |
url = url.replace(" ","%20"); | |
System.out.println("URL=> "+url); | |
DownloadManager downloadManager = (DownloadManager) ((Activity) baseActivity).getSystemService(Context.DOWNLOAD_SERVICE); | |
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); | |
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) | |
.setAllowedOverRoaming(false) | |
.setTitle(fileName) | |
.setDescription("Downloading "+fileName) | |
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) | |
.setMimeType(mimeType) | |
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); | |
downloadManager.enqueue(request); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment