Extend the system service DownloadManager with pauseDownload and resumeDownload. We can use this library like System "DownloadManager"
- Support Pause and Resume to download
- Support get downloading speed
- Support all functions of system downloadmanager
- Support url icon
Add the following code snippet in build.gralde
compile 'com.android.support.test.espresso:espresso-core:2.2.2'Place download_110.aar into the libs of your project. Get the jar from the directory 'download_arr' compile 'com.leaf:downloadmanager:1.1.0'<dependency>
<groupId>com.leaf</groupId>
<artifactId>downloadmanager</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency><uses-permission android:name="android.permission.INTERNET"/>
DownloadManager.getInstance(mContext).pauseDownload(downloadId); DownloadManager.getInstance(mContext).resumeDownload(downloadId); DownloadManager.getInstance(mContext).remove(downloadId); DownloadManager.getInstance(mContext).restartDownload(downloadId); DownloadManager.getInstance(mContext).getDownloadSpeed(downloadId); DownloadManager.getInstance(mContext).removeAll(); String selection = Downloads.Impl.COLUMN_STATUS + " = " + Downloads.Impl.STATUS_SUCCESS;
String orderBy = Downloads.Impl._ID + " DESC";
Cursor cursor = context.getContentResolver().query(Downloads.Impl.CONTENT_URI, null, selection, null, orderBy);like usage of system downloadmanager
public static void download(Context mContext, String videoUrl, String iconUrl, String userAgent, String title, String fileName, String mimeType) {
if (TextUtils.isEmpty(videoUrl)) {
return;
}
String url = videoUrl;
Uri uri = Uri.parse(url);
DownloadManager.Request req = new DownloadManager.Request(uri);
req.addRequestHeader("User-Agent", userAgent);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
req.setDestinationInExternalFilesDir(mContext, Environment.DIRECTORY_DOWNLOADS, fileName);
req.setTitle(title);
req.setIconUrl(iconUrl);
req.setDescription("click and open");
req.setMimeType(mimeType);
DownloadManager.getInstance(mContext).enqueue(req);
}