I’m using the DownloadManager class to programatically download a file. All works fine but I can’t get the download completed notifcation to persist. It disappears immediately once the download has completed. Here’s my code:
Request rqtRequest = new Request(Uri.parse(((URI) vewView.getTag()).toString()));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
rqtRequest.setShowRunningNotification(true);
} else {
rqtRequest.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
((DownloadManager) getSystemService(DOWNLOAD_SERVICE)).enqueue(rqtRequest);
I’ve seen some questions around the web relating to this but I couldn’t find a solution.
DownloadManagerdoesn’t support a completion notification on Gingerbread; you have to display it yourself.Use a BroadcastReceiver to detect when the download finishes and show your own notification:
and register it in your manifest:
Also,
setNotificationVisibilitywas added in API level 11 (Honeycomb) not ICS. I’m not sure if your use of the ICS constant is deliberate or not, but you can change your code to the following to the use the system notification on Honeycomb as well: