我已经为下载进度条做了这段代码,但如果用户不小心点击了按钮,我也想取消下载任务。我无法实现这件事.can任何人请帮助我摆脱这一点。
提示:我是android java的新手,所以请提前给我解释一下所有详细的answer.thanks。
String url = "URL";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Some descrition");
request.setTitle("Some title");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "PDF_demo.ext");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
if (manager != null) {
long downloadID = manager.enqueue(request);
}发布于 2019-12-10 14:39:16
在the document中,尝试使用:
DownloadManager.remove(downloadID)https://stackoverflow.com/questions/59261355
复制相似问题