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?
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With