Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

notification disappears - Android DownloadManager

Solution: API 11 is needed see answer below!

Easy Question: After downloading a File with the implemented DownloadManager the Notification disappears. How do I force the Notification to stay after Download?

I tried to use VISIBILITY_VISIBLE_NOTIFY_COMPLETED, but i do not know how i can use it

Thank for any kind of help to solve this problem ;)

EDIT: Code

public class BgDL extends Activity {

private DownloadManager mgr = null;
private long id;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);

    mgr = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

    Request request = new Request(Uri.parse(getIntent().getStringExtra("URL")));

    id = mgr.enqueue(request
            .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "UPDATE")
            .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI|DownloadManager.Request.NETWORK_MOBILE)
            .setAllowedOverRoaming(false)
            .setTitle("APP update")
            .setDescription("New version "+getIntent().getDoubleExtra("OV", 0.0))


    );

   registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

}
BroadcastReceiver receiver = new BroadcastReceiver () {


      public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(mgr.ACTION_DOWNLOAD_COMPLETE) ){
            unregisterReceiver(receiver);
            finishActivity(99);
        }
      }


}; 

}

like image 369
malger Avatar asked Jun 20 '12 21:06

malger


People also ask

How do I see download progress in notification bar?

Generally, the progress indicators in android are implemented by using the ProgressBar class. To display the progress indicators in our app, we need to add the progress bar to our notification by calling setProgress(max, progress, false) method and then issue the notification.

How do I get download progress notification on Samsung?

Go to Settings - Apps - All Apps - Chrome - Notifications. Now enable show notification button and in sub categories enable notification for downloads. Follow same procedure for any other browser.

How do I turn off Download Manager notifications?

This issue seemed to be fixed for a few people by doing the following: Go to settings -> Apps and Notifications -> see all apps -> three dot menu -> show system. Scroll to Download Manager. Clear cache, clear storage, force stop, disable, enable.


1 Answers

Add the correct flag to your request:

Request request = new Request(Uri.parse(getIntent().getStringExtra("URL")));

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

Reference:

http://developer.android.com/reference/android/app/DownloadManager.Request.html#setNotificationVisibility(int)

Control whether a system notification is posted by the download manager while this download is running or when it is completed. If enabled, the download manager posts notifications about downloads through the system NotificationManager. By default, a notification is shown only when the download is in progress.

http://developer.android.com/reference/android/app/DownloadManager.Request.html#VISIBILITY_VISIBLE_NOTIFY_COMPLETED

This download is visible and shows in the notifications while in progress and after completion.

like image 63
Blundell Avatar answered Sep 26 '22 19:09

Blundell