2

我不希望通知管理器(状态栏)打开活动。相反,当单击通知时,它只是被取消,并且不会发生任何事情。

4

3 回答 3

4

当你创建PendingIntent一个空的 Intentnew Intent()

PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)

并为通知设置 FLAG_AUTO_CANCEL 标志

notification.flags |= Notification.FLAG_AUTO_CANCEL;
于 2012-05-29T07:41:47.193 回答
4
final NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, null);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);

与其在意图中传递类,不如传递 null 或使用 intent() 默认构造函数。如果有助于欣赏。

于 2012-05-29T07:46:14.507 回答
0

finish()创建一个从中调用的空活动onCreate()并将其设置在PendingIntent. 一个空的(null)是不允许的,所以这是你最好的选择,AFAIK。

于 2012-05-29T07:41:25.850 回答