![]() When a download cannot proceed because the maximum number of parallel downloadsĪre already in progress, it will be in the Download.STATE_QUEUED state. This would normally be done whenĬreating the DownloadManager, as in the example above. The maximum number of parallel downloads can be set by callingĭtMaxParallelDownloads(). Setting the maximum number of parallel downloads Requirements with DownloadManager.getNotMetRequirements(). Will be in the Download.STATE_QUEUED state. When a download cannot proceed because the requirements are not met, it class, requirements, /* foreground= */ false ) sendSetRequirements ( context, MyDownloadService. Pausing and resuming all downloadsĪll downloads can be paused and resumed as follows: Stop reasons are persisted in theĭownloadIndex, and so are retained if the application process is killed and When a download has a non-zero stop reason, it will be in theĭownload.STATE_STOPPED state. Retained, and clearing the stop reason will cause the download to continue. Setting a stop reason does not remove a download. Single download, except that contentId should be set to null. Setting and clearing the stop reason for allĭownloads works the same way as setting and clearing the stop reason for a ![]() Multiple reasons for stopping downloads can use different values to keep track Where stopReason can be any non-zero value ( Download.STOP_REASON_NONE = 0 isĪ special value meaning that the download is not stopped). ![]() STOP_REASON_NONE, /* foreground= */ false ) sendSetStopReason ( context, MyDownloadService. class, contentId, stopReason, /* foreground= */ false ) // Clear the stop reason for a single download. Set the stop reason for a single download. The exampleīelow shows how to create a download request: For adaptive streams DownloadHelper can be used to helpīuild a DownloadRequest, as described further down this page. To add a download you need to create a DownloadRequest and send it to yourĭownloadService. See DemoUtil in the demo app for a concrete example. setRequirements ( requirements ) downloadManager. downloadManager = new DownloadManager ( context, databaseProvider, downloadCache, dataSourceFactory, downloadExecutor ) // Optionally, setters can be called to configure the download manager. Executor downloadExecutor = Runnable: : run // Create the download manager. Applications that // already have an executor for background downloads may wish to reuse their existing executor. Passing an executor that uses multiple threads will speed up // download tasks that can be split into smaller parts for parallel execution. Using Runnable::run will cause each download task to // download data on its own thread. Factory () // Choose an executor for downloading data. dataSourceFactory = new DefaultHttpDataSource. downloadCache = new SimpleCache ( downloadDirectory, new NoOpCacheEvictor (), databaseProvider ) // Create a factory for reading the data from the network. databaseProvider = new StandaloneDatabaseProvider ( context ) // A download cache should not evict media, so should use a NoopCacheEvictor. Note: This should be a singleton in your app. You can useĭownloadNotificationHelper.buildProgressNotification to create aįinally, you need to define the service in your AndroidManifest.xml file:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |