Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void fileDownload(String url, String fileName) {
- //SET CUSTOM PATH HERE. Example:
- File direct = new File(Environment.getExternalStorageDirectory() + "/Mods");
- //The code above will save the file to /sdcard/Mods
- if (!direct.exists()) {
- direct.mkdirs();
- }
- DownloadManager mgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
- Uri downloadUri = Uri.parse(url);
- DownloadManager.Request request = new DownloadManager.Request(downloadUri);
- request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
- .setAllowedOverRoaming(false).setTitle("Downloading Mod")
- .setDestinationInExternalPublicDir("Mods", fileName);
- //Make the string above the same as you did before. In this case, it was "/Mods"
- mgr.enqueue(request);
- }
- //To download a file, call
- // fileDownload(URL_HERE, FILE_NAME_HERE);
- //Code by someone else, I only improved it
Add Comment
Please, Sign In to add comment