通知点击事件时的通话活动

时间:2010-09-08 09:19:46

标签: android

我想在用户下拉通知并点击该通知时调用该活动...我该怎么做?

3 个答案:

答案 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);