![]() dataSourceFactory = new DefaultHttpDataSource. Factory () // Choose an executor for downloading data. Using Runnable::run will cause each download task to // download data on its own thread. Passing an executor that uses multiple threads will speed up // download tasks that can be split into smaller parts for parallel execution. Applications that // already have an executor for background downloads may wish to reuse their existing executor. Executor downloadExecutor = Runnable: : run // Create the download manager. downloadManager = new DownloadManager ( context, databaseProvider, downloadCache, dataSourceFactory, downloadExecutor ) // Optionally, setters can be called to configure the download manager. setRequirements ( requirements ) downloadManager. See DemoUtil in the demo app for a concrete example. ![]() To add a download you need to create a DownloadRequest and send it to yourĭownloadService. 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. Set the stop reason for a single download. class, contentId, stopReason, /* foreground= */ false ) // Clear the stop reason for a single download. STOP_REASON_NONE, /* foreground= */ false ) sendSetStopReason ( context, MyDownloadService. 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). Setting and clearing the stop reason for allĭownloads works the same way as setting and clearing the stop reason for a Single download, except that contentId should be set to null. Setting a stop reason does not remove a download. Retained, and clearing the stop reason will cause the download to continue. 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. When a download cannot proceed because the requirements are not met, it class, requirements, /* foreground= */ false ) sendSetRequirements ( context, MyDownloadService. Will be in the Download.STATE_QUEUED state. Setting the maximum number of parallel downloads Requirements with DownloadManager.getNotMetRequirements(). ![]() The maximum number of parallel downloads can be set by callingĭtMaxParallelDownloads(). This would normally be done whenĬreating the DownloadManager, as in the example above. 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.
0 Comments
Leave a Reply. |