Android: How to use the boot manager class?

I want to download a binary file from a url. Can I use the Android boot manager class that I found here for the DownloadManager class ?

+7
source share
3 answers

Is it possible to use the Android boot manager class that I found here.

Yes, although this is only available with the Android API level 9 (version 2.3). Here is an example project demonstrating the use of DownloadManager .

+26
source

Use the DownloadManager class (only GingerBread and newer)

GingerBread brought a new DownloadManager function that makes it easy to upload files and delegate the hard work of handling threads, threads, etc. into the system.

First, look at a useful method:

 /** * @param context used to check the device version and DownloadManager information * @return true if the download manager is available */ public static boolean isDownloadManagerAvailable(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return true; } return false; } 

The name of the method explains everything. Once you are sure that DownloadManager is available, you can do something like this:

 String url = "url you want to download"; DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setDescription("Some descrition"); request.setTitle("Some title"); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "name-of-the-file.ext"); // get download service and enqueue file DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); 

Download progress will be displayed in the notification panel.

+6
source
 DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Uri uri = Uri.parse("http://www.example.com/myfile.mp3"); DownloadManager.Request request = new DownloadManager.Request(uri); request.setTitle("My File"); request.setDescription("Downloading"); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationUri(Uri.parse("file://" + folderName + "/myfile.mp3")); downloadmanager.enqueue(request); 
+3
source

All Articles