单击通知栏上的图像后,如何进行活动? 我该如何制作意图? 感谢。
public class AlarmService extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Check your fridge";
CharSequence message = "It's time to eat!";
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(), 0);
Notification notif = new Notification(R.drawable.fridge_icon3,
"Keep Fridge", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, contentIntent);
notif.defaults |= Notification.DEFAULT_SOUND;
notif.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(1, notif);
}
}
答案 0 :(得分:1)
您发布的代码已经有意图,例如你在contentIntent中有新的Intent()。它并没有多大用处,因为你没有用任何东西填充它。你需要这样的事情。
Intent notificationIntent = new Intent(this, MyAvtivity.class);
// modify the intent as nessasary here.
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
用户指南here