我想在用户下拉通知并点击该通知时调用该活动...我该怎么做?
答案 0 :(得分:15)
在setLatestEventInfo()
对象上拨打Notification
,提供PendingIntent
,当他们点击通知抽屉中的条目时,会启动您的活动。以下a sample project证明了这一点。
答案 1 :(得分:11)
假设notif
是您的Notification
对象:
Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;
答案 2 :(得分:1)
以下是点击通知时调用活动的代码
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);