开发者

Call activity when on notification tap event

开发者 https://www.devze.com 2023-01-15 01:12 出处:网络
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 Pendin

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消