我有以下代码来创建状态栏通知:
public void txtNotification(int id, String msg){
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(android.R.drawable.sym_action_email, msg, System.currentTimeMillis());
// The PendingIntent will launch activity if the user selects this notification
Intent intent = new Intent(this, MainActivity.class)
intent.putExtra("yourpackage.notifyId", id);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, intent, 0);
notification.setLatestEventInfo(this, "title", msg, contentIntent);
manager.notify(id, notification);
}
当通知被点击时,我想调用一个方法,并且最好能够访问通知的id。
提前感谢您的帮助,
Tim
(编辑:阅读了第一个答案后,我更新了我的代码,但是我仍然不知道如何监听意图)