Call activity when on notification tap event

28,932

Solution 1

Call setLatestEventInfo() on the Notification object, supplying a PendingIntent that will start your activity when they tap on your entry in the notification drawer. Here is a sample project demonstrating this.

Solution 2

Assuming that notif is your Notification object:

Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;

Solution 3

Here is the code to call activity when notification is clicked

Notification notif = new Notification(R.drawable.ic_launcher,"List of Contacts...", System.currentTimeMillis());
Intent notificationIntent = new Intent(context,AllContacts.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,            notificationIntent, 0);
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
Share:
28,932
Kandha
Author by

Kandha

Android Developer

Updated on July 21, 2022

Comments

  • Kandha
    Kandha almost 2 years

    I want to call the activity when user pull down the notification and tap on that notification. How can I do that?