我有一個可能顯示通知的服務,問題出現在通知設置完成後,點擊時或者刷卡時都不會清除。我使用的標誌Notification.FLAG_AUTO_CANCEL
,但它似乎並沒有做任何事情..通知用戶清除通知或點擊一次
private NotificationManager nm;
nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
private final int NOTIFY_ID = 1;
private void showNotification(String date, String name) {
try{
CharSequence text = "You have new Event";
Notification notification = new Notification(R.drawable.small_icon, text, System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, viewEvents.class).putExtra("date", date), 0);
notification.setLatestEventInfo(this, name, "Date: "+date, contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.FLAG_AUTO_CANCEL;
nm.notify(NOTIFY_ID, notification);
}catch(Exception e){
Log.i("Notification",e.toString());
}
}
那我做錯了嗎?
我也評論說:「Notification.FLAG_AUTO_CANCEL」後,我發現,這是行不通的,我試圖將它設置爲「標誌」和「默認」,但兩者都不起作用。 – Khaled