如何在Android中通知中添加取消处理能力?

时间:2015-04-04 17:34:22

标签: android download android-download-manager request-cancelling

我有这个代码供下载管理器下载,

代码:

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;
        }
    }

现在我想点击通知中的下载处理,当前下载被取消。

1 个答案:

答案 0 :(得分:0)

如果要取消对下载通知的下载操作,则需要使用自定义通知而不是内置通知。 或者您可以使用cancle动作打开下载列表,用户单击通知

您可以阅读有关下载管理器点击操作here

的更多信息