我已经创建了一个应用程序,并通过一个事件在android通知栏中添加了通知。现在我需要示例如何从事件通知栏中删除该通知??
发布于 2010-08-29 23:04:24
这很简单。你必须在你的NotificationManager上调用cancel
或cancelAll
。cancel方法的参数是需要取消的通知的ID。
查看接口:http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)
发布于 2011-12-20 20:54:47
你可以试试这个快速代码
public static void cancelNotification(Context ctx, int notifyId) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) ctx.getSystemService(ns);
nMgr.cancel(notifyId);
}
发布于 2014-09-15 22:49:07
您还可以在通知管理器上调用cancelAll
,因此您甚至不必担心通知ids。
NotificationManager notifManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifManager.cancelAll();
编辑:我被否决了,所以也许我应该指定这只会从你的应用程序中删除通知。
https://stackoverflow.com/questions/3595232
复制相似问题