取消通知从服务开始

时间:2014-09-05 11:34:11

标签: android service notifications android-notifications

我正在编写一个应用程序,其中我需要显示来自服务的通知。我使用标志Foreground_service来启动通知。现在我想在不停止服务的情况下取消此通知(来自活动)。有什么建议吗?

1 个答案:

答案 0 :(得分: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

相关问题