关闭安卓通知 [英] Close android Notification
本文介绍了关闭安卓通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在服务启动时创建了通知,但我不知道如何在服务停止或销毁时关闭该通知.有什么想法.
i have create notification when service start but i have not idea how to close that notification when service stop or on destroy. have any idea.
以下代码在服务启动时启动通知.
following code that start notification when service start.
String ns = Context.NOTIFICATION_SERVICE;
final int KEEPUS_NOTIFICATION_ID = 1;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
Notification notification = new Notification(R.drawable.notification_icon1, ticker_text, System.currentTimeMillis());
Intent notificationIntent = new Intent(context, KeepusActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, ticker_content_title, ticker_content_text,contentIntent);
mNotificationManager.notify(KEEPUS_NOTIFICATION_ID, notification);
推荐答案
use notification manager #cancel with your notification id
use notification manager #cancel with your notification id
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(KEEPUS_NOTIFICATION_ID);
这篇关于关闭安卓通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文