Android: DownloadManager - Notification Sticking

I am downloading an image from my server using Download Manager.

It downloads the file in order and places it where I want. But for some reason the message is notified and I cannot delete it. The code for the download manager is as follows:

mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

Uri uri = Uri.parse("URL"));

long enqueue = mDownloadManager.enqueue(new DownloadManager.Request(uri)
            .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
            .setAllowedOverRoaming(false)
            .setTitle("Title")
            .setDescription("File description")
            .setDestinationInExternalPublicDir("Folder", "Filename")
            .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE));

BroadcastReceiver onComplete = new BroadcastReceiver() {
    public void onReceive(Context ctxt, Intent intent) {
        Toast.makeText(getApplicationContext(), "Download Completed", Toast.LENGTH_SHORT).show();
    }
 };

How to delete a notification after downloading it? .

I tried to set all the different notification visibility modes with no luck. Is there anything I can do from BroadcastReceiver after it is completed?

+5
source share
1 answer

. BroadcastReceiver DownloadManager.

BroadcastReceiver onComplete = new BroadcastReceiver() {
    public void onReceive(Context ctxt, Intent intent) {
        Toast.makeText(getApplicationContext(), "Download Completed", Toast.LENGTH_SHORT).show();

        // Get the download_id of the completed download.
        long download_id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

        // Remove the completed download from the DownloadManager
        mDownloadManager.remove(download_id);
    }
 };

, mDownloadManager.remove(download_id) . , , .

+8

All Articles