我想创建一个通知,当用户按下该通知并且没有其他行为时会自动清除。下面的通知工作正常,但是当我按下它时,它将我带到活动“MyActivity”(即使不想使用它,甚至必须定义意图似乎有点不必要...)如何在用户点击通知时取消通知?
使用FLAG_AUTO_CANCEL似乎没有任何影响。
更新:对不起,我已经找到了FLAG_AUTO取消不工作,即通知从状态栏清除。我想我真的想写一个什么都不做的意图(或者完全删除意图)。
代码...
Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis());
//Define the expanded message and intent
Context context = getApplicationContext();
CharSequence contentTitle = res.getString("My content title");
Intent notificationIntent = new Intent(this, MyActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//Pass the notification to the notification manager
mNotificationManager.notify(1, notification);