0

I built a Cordova app that shows a notification on Android. When the notification is clicked and the app was closed in the meantime I want the app (the cordova activity) to be started again.

This is how I build the notification in a Cordova Android plugin:

Context context = this.cordova.getActivity();
Intent resultIntent = new Intent(context, CordovaActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
Notification noti = new Notification.Builder(context)
  .setContentTitle("MyApp")
  .setContentText("foobar")
  .setContentIntent(pIntent)
  .build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);

The notification shows up correctly, but doesn't start my app when clicking on it. I am not sure what class to provide for the Intent.

How do I have to create the notification to make this work?

Zardoz
  • 14,339
  • 21
  • 79
  • 126

2 Answers2

0

copy of this question , you just have to replace your package name with yours

Community
  • 1
  • 1
Ranjith Varma
  • 405
  • 3
  • 11
0

The solution is to use the MainActivity.class for the intent (instead of the CordovaActivity class). It can be found (and must be imported) in the package that is named like the widget id which is defined in the config.xml of your Cordova project.

Zardoz
  • 14,339
  • 21
  • 79
  • 126