如何从通知中启动活动

时间:2011-07-05 15:08:09

标签: java android notifications

使用以下代码,我希望通知在单击时消失。不要开始任何活动。我该怎么做?

NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.icon, "hello", System.currentTimeMillis());
n.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(ctx, NotifyActivity.class);
PendingIntent i = PendingIntent.getActivity(ctx, 0, intent, 0);
n.setLatestEventInfo(ctx, "title", "content", i);
nm.notify(1, n);

1 个答案:

答案 0 :(得分:0)

我知道我过去采取的一种方法是不填写用于创建PendingIntent的Intentu的任何信息。在您的示例中,您只需删除传递给构造函数的参数“intent”。

我不完全确定你是否可以为挂起的意图传递null到setLatestEventInfo,但是如果你不能,我提出的解决方案应该可行。