Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 427
Suresh Kerai Avatar asked Jun 30 '11 10:06

Suresh Kerai


People also ask

How do I get rid of a notification that won't go away Android?

To remove a persistent notification on Android as fast as possible, first, press-and-hold on it. Alternatively, swipe the notification left or right to reveal a gear icon on either side, and then tap on it. The notification expands. Tap on “Turn off notifications” at the bottom.


1 Answers

use notification manager #cancel with your notification id

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(KEEPUS_NOTIFICATION_ID);
like image 63
appsthatmatter Avatar answered Oct 12 '22 23:10

appsthatmatter