Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the notification icon from the status bar

Tags:

android

I am displaying an icon in status bar.Now I want to remove that icon immediately when I open that content, after some time if we receive any alert, that icon will be displayed again. How can I do this?

like image 312
Pinki Avatar asked May 15 '10 10:05

Pinki


People also ask

How do I remove icon from notification bar?

How do I hide the status bar on Android? With a stock Android phone, press and hold Settings until System Settings appears. Select System UI Tuner > Status Bar, and turn off all the options.

How do I get notification icons on my status bar?

Scrolling down the Quick Menu from the top of the screen, tap the Settings icon > "Display" > "Status bar icon manager" and then you can enable or disable the icons on the status bar.


1 Answers

Use the NotificationManager to cancel your notification. You only need to provide your notification id.

https://developer.android.com/reference/android/app/NotificationManager.html

private static final int MY_NOTIFICATION_ID= 1234;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(MY_NOTIFICATION_ID, notification);

The example code is not complete. It depends on how your created your notification. Just make sure you use the same id to cancel your notification as you used when you created your notification.

To cancel:

mNotificationManager.cancel(MY_NOTIFICATION_ID);
like image 77
Vidar Vestnes Avatar answered Sep 22 '22 03:09

Vidar Vestnes