Close android Notification

点点圈 提交于 2020-01-24 03:30:53

问题


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);

回答1:


use notification manager #cancel with your notification id

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(KEEPUS_NOTIFICATION_ID);


来源:https://stackoverflow.com/questions/6533360/close-android-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!