1

I have this code for download by download manger,

code:

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

Download class:

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

Now I want when click on download processing in notification, current download be cancelled.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mehdi Rahimi
  • 153
  • 2
  • 13
  • 1
    Take note that some Samsung Galaxy devices like S5 and S6 are returning false for the isDownloadManagerAvailable() call. I'm speaking for my experience, the best way to know if the DownloadManager is avaiable is simply checking the android version is above or equals to Gingerbread. – icastell Jun 09 '15 at 17:20

1 Answers1

0

If you want to cancel download action to the download notification you need to use custom notification instead of built-in notification. or you can open download list with cancle action one the user click in the notification

You can read more about download manager click action here

Basbous
  • 3,927
  • 4
  • 34
  • 62