Cordova plugin notification (java) not included in application - android

I am not an Android developer, but I need to make an application, so since I know some HTML / JavaScript / CSS, I decided to use PhoneGap (Cordova). I use a plugin called the download manager ( github ), which downloads files and displays a progress notification. Everything works, but I want to return me to the main activity of my application when I click on a notification, but this does not happen.

This file is the file responsible for the download and notification, the following code:

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 not get it to work, when I click the notification, nothing happens. What's wrong? Sorry for the bad english.

+8
java android cordova
source share
3 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.

+4
source share

Try the following:

  notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 

Replace it with your variables. Hope it works.

0
source share

It seems that the author of the library clicked on the notification to cancel the download. In any case, the original intention wrapped with PendingIntent does not indicate the beginning of the action.

you must change:

 intent = new Intent (); intent.putExtra("cancel_download", 1); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); 

in

 intent = new Intent (); intent.setComponent(cordova.getActivity.getComponentName()); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); 
0
source share

All Articles