【发布时间】:2012-02-24 20:17:19
【问题描述】:
我有一个应用程序可以通过某种提醒来提醒用户。这些提醒会像通知一样显示。当用户单击这些通知中的任何一个时,它应该显示有关该警报的其他信息。这基本上是通过调用具有特定参数的活动来完成的。
这就是我的工作:
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,但是我第二次点击它时没有显示活动。
我还能尝试什么?我在这里完全没有想法。 谢谢
【问题讨论】:
标签: java android notifications