Call activity when on notification tap event
I want to call the activity whe开发者_如何学Gon user pull down the notification and tap on that notification. How can I do that?
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.
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;
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);
精彩评论