1
。我有一个下载管理器下载这段代码,如何在android中的通知中添加下载处理的取消功能?
代码:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription(name);
request.setTitle("دانلود ویدیو");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir("/mlindr/101ideas/video", video);
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
//manager.enqueue(request);
long id = manager.enqueue(request);
下载类:
public static boolean isDownloadManagerAvailable(Context context) {
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
return false;
}
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList");
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
} catch (Exception e) {
return false;
}
}
现在我想,当点击在通知下载处理,当前下载被取消。
谢谢你的任何帮助。
注意到,像S5和S6一些三星Galaxy设备正在返回的错误isDownloadManagerAvailable()调用。我在讲我的经验,知道DownloadManager是否可用的最好方法是简单地检查Android版本是否高于或等于姜饼。 – icastell 2015-06-09 17:20:42