代码拉取完成,页面将自动刷新
同步操作将从 Bvin/DownloadModule 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#DownloadModule Demo https://git.oschina.net/bvin/AndroidTest_Download.git
//网络
<uses-permission android:name="android.permission.INTERNET" />
//下载管理器的访问权限
<uses-permission android:name="cn.bvin.permission.ACCESS_DOWNLOAD_MANAGER" />
//访问网络状态
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
//唤醒
<uses-permission android:name="android.permission.WAKE_LOCK" />
//外部储存
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
//DownloadProvider 必须
<provider
android:name="cn.bvin.lib.module.downloads.DownloadProvider" android:authorities="cn.bvin.lib.module.downloads" />
//DownloadService 必须
<service
android:name="cn.bvin.lib.module.downloads.DownloadService" />
//DownloadReceiver 非必须
<receiver
android:name="cn.bvin.lib.module.downloads.DownloadReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
//开始下载
DownloadManager dm = new DownloadManager(getContentResolver(), getPackageName());
DownloadManager.Request request = new Request(srcUri);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/");
long currentDownloadId = dm.enqueue(request);
//暂停
dm.pauseDownload(currentDownloadId);
//恢复
dm.resumeDownload(currentDownloadId);
//取消或删除
dm.remove(currentDownloadId);
//查询,通过cursor可以查询所有下载字段信息
DownloadManager.Query query = new Query();
query.setFilterById(currentDownloadId);
Cursor cursor = dm.query(query);
//也可以通过下面方式来查询
Uri uri = ContentUris.withAppendedId(Downloads.CONTENT_URI, currentDownloadId);
Cursor cursor = getContentResolver().query(uri, new String[]{Downloads.COLUMN_CURRENT_BYTES,
Downloads.COLUMN_TOTAL_BYTES}, null, null, null);
//通过ContentObserver来监听当前下载任务
getContentResolver().registerContentObserver(Downloads.CONTENT_URI, true, observer);
通过Cursor可以把以下信息查出来
| uri| _data | status |total_bytes|current_bytes|title |------------|-----------|--------|--------|--------| | 下载地址 | 下载文件路径| 下载状态 |总共大小|当前下载字节|下载文件标题 [1]: https://git.oschina.net/bvin/AndroidTest_Download.git [2]: https://github.com/bumptech/glide/wiki [3]: http://bumptech.github.io/glide/javadocs/latest/index.html [4]: https://www.jetbrains.com/idea/download/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。