I'm not an android developer, but I need to make an app, so since I know some HTML/JavaScript/CSS I decided to use PhoneGap (Cordova). I use a plugin called download manager (github) which downloads files and display a progress notification. Everything works, but I want to bring me back to the main activity of my app once I click on the notification, but that doesn't happen.
This is the file responsible for the download and notification, the involved code is below:
intent = new Intent();
intent.putExtra("cancel_download", 1);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
pend = PendingIntent.getActivity(cordova.getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mNotifyManager = (NotificationManager) cordova.getActivity().getSystemService(Activity.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(cordova.getActivity())
.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle(notificationTitle)
/*.setSubText("Tap to CANCEL")*/
.setTicker(ticker)
.setContentIntent(pend)
.setContentText("0% - " + fileName);
mNotificationId = new Random().nextInt(10000);
...
...
//While(downloading)
if(useNotificationBar) {
mBuilder.setProgress(100, newProgress, false);
mBuilder.setContentText(step + "% - " + fileName);
mBuilder.setContentIntent(pend);
mNotifyManager.notify(mNotificationId, mBuilder.build());
}
I can't make it work when I click the notification nothing happens. What is wrong? Sorry for bad English.
Change
pend = PendingIntent.getActivity(cordova.getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
to
pend = PendingIntent.getActivity(cordova.getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Hope this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With