notification disappears - Android DownloadManager
Asked Answered
K

1

15

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


}; 

}

Keiko answered 20/6, 2012 at 21:12 Comment(2)
Plz post some code to go off of. ThnxBalladist
@malger, did you manage to solve this? My notification disappears too.Nightdress
C
33

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.

Chalmers answered 20/6, 2012 at 21:27 Comment(6)
thank you for help, but problem isn't solved yet! I get: 'VISIBILITY_VISIBLE_NOTIFY_COMPLETED cannot be resolved or is not a fieldKeiko
but i have imported it: " import android.app.DownloadManager; import android.app.DownloadManager.Request;"Keiko
it needs a minSdk of 11 you have probably got 9? (in your AndroidManifest) API url I linked: "Since: API Level 11"Chalmers
ohh..... mh that seems to be the problem. but what can I do to get this work under gingerbread API 9? Any kind of solution?Keiko
I guess i have to use NotificationManager instead?Keiko
Nopes, i think you guys are wrong. On earlier devices, you have to use the Request.setShowRunningNotification(true); to show the download notification. It's right there in the docs. developer.android.com/reference/android/app/…Nightdress

© 2022 - 2024 — McMap. All rights reserved.