我创建了一个通知。当用户在 android 操作系统中单击通知时,它会成功启动所需的活动。它在我的 Activity_Send.class 上调用 OnCreate。我的问题是,我可以访问有关该通知的任何信息吗?通知的标题,或 ID,甚至是否可以传递我在创建通知时可以设置的参数,当它调用我的活动时我可以检索这些参数?
下面的代码是我用来创建我的通知的代码......修订后的代码
private static void notice(String msgfrom, String msg) {
Intent intent = null;
String title;
TaskStackBuilder stackBuilder = TaskStackBuilder.create(appctx);
title = "New message from " + msgfrom;
SendUser = msgfrom; // Who we sending message to?
intent = new Intent( appctx, Activity_Send.class);
intent.putExtra("from", msgfrom);
intent.putExtra("id",Integer.toString(NoticeCount));
if (whoscreen != null) { stackBuilder.addNextIntent(whoscreen); }
stackBuilder.addNextIntent(intent);
//PendingIntent pintent = PendingIntent.getActivity(appctx,NoticeCount,intent, 0);
PendingIntent pintent = stackBuilder.getPendingIntent(NoticeCount, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder nb = new NotificationCompat.Builder(appctx);
nb.setSmallIcon(R.drawable.pp);
nb.setContentTitle(title);
nb.setContentText(modmsg);
nb.setAutoCancel(true);
nb.setContentIntent(pintent);
Notification notification = nb.build();
NotificationManager NM = (NotificationManager) appctx.getSystemService(NOTIFICATION_SERVICE);
NM.notify(NoticeCount, notification);
NoticeCount = NoticeCount +1;
}