我有一个应用程序通过某种提醒来提醒用户。这些提醒显示为通知。当用户点击任何这些通知时,它应该显示关于该警报的附加信息。这基本上是通过调用具有特定参数的活动来完成的。单击“通知”图标时只显示一次活动
这是我做的:
NotificationManager mNotificationManager = (NotificationManager) MyApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.reminder2, reminder.Title, System.currentTimeMillis());
Intent notificationIntent = null;
notificationIntent = new Intent(MyApplication.getContext(), ReminderActivity.class);
notificationIntent.putExtra("idnotification", reminder.ID);
PendingIntent contentIntent = PendingIntent.getActivity(MyApplication.getContext(), reminder.ID, notificationIntent, 0);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.FLAG_INSISTENT;
notification.setLatestEventInfo(MyApplication.getContext(), "Reminder", reminder.Title, contentIntent);
mNotificationManager.notify(reminder.ID, notification);
这似乎是工作,但问题是,如果我点击一个通知一个以上的时间它会创建一个新的活动,而不是显示一个已经可见。
我试着为PendingIntent设置标志,但没有运气。我试着用FLAG_CANCEL_CURRENT,FLAG_NO_CREATE,FLAG_ONE_SHOT,FLAG_UPDATE_CURRENT。唯一一个接近我需要的是FLAG_ONE_SHOT,但第二次点击它并不显示活动。
我还能试试吗?我在这里完全没有想法。 谢谢
感谢您的回复。我仍然无法实现它,我对尝试组合和组合以及在这个问题上花费时间感到厌倦。我想我会在用户点击时从状态栏中删除通知。问候 – LEM 2012-02-27 00:48:50