Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova plugin (java) notification doesn't go to app - android

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.

like image 446
Franz Tesca Avatar asked Feb 01 '17 20:02

Franz Tesca


1 Answers

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.

like image 69
Naresh Kumar Avatar answered Oct 27 '22 00:10

Naresh Kumar