2014-09-05 57 views
0

我正在寫一個應用程序,我需要顯示來自服務的通知。我使用標誌Foreground_service開始通知。現在我想在不停止服務的情況下取消此通知(來自活動)。任何建議嗎?取消通知從服務開始

回答

1

你應該使用一個NotificationManager對象取消通知時,使用相同的ID(即你用來給通知)並傳遞到NoticationManager.cancel(INT):

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
notificationManager.cancel(1); // here 1 is the id of that notification 

進一步可以從下面看關於通知管理器

http://developer.android.com/reference/android/app/NotificationManager.html#cancel%28int%29

+0

此方法在從服務設置通知時不起作用。這用於其他情況。 – techroid 2014-09-05 11:49:31