-
Notifications
You must be signed in to change notification settings - Fork 90
Open app when notification is clicked
Gilles Bajart edited this page Dec 29, 2016
·
7 revisions
So first, we go in the file RadioPlayerService.java in the function buildNotification(): We delete this line of code:
Intent intentOpenPlayer = new Intent(NOTIFICATION_INTENT_OPEN_PLAYER);
and replace it with:
Intent notificationIntent = new Intent();
//replace "be.medias.pulseair" by your package name
//replace "be.medias.pulseair.Home" by the path of your activity you want to open
notificationIntent.setClassName("be.medias.pulseair", "be.medias.pulseair.Home");
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Again, delete this line of code:
PendingIntent openPending = PendingIntent.getBroadcast(this, 31, intentOpenPlayer, 0);
and replace it with:
PendingIntent openPending = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Here it is, now your notification opens the activity of your choice 👍