Android Question How to hide notification icon in status bar?

Inman

Well-Known Member
Licensed User
Longtime User
I have foreground service on an app targeting SDK 26 and therefore there will be a persistent notification as long as the service is up. I know that I can customise this notification using Service.AutomaticForegroundNotification. What I am trying to do is to hide the notification icon in such a way that it will only be visible if the user pulls down the notification bar from top. Other times the icon should not be visible at the status bar on top.

On Android 8.0 and 8.1, I could achieve this by setting notification priority. I set the importance as IMPORTANCE_MIN and it works great, even though it is specifically mentioned not to use it in foreground services. Any idea why there is no error?

But when I tried the same app on an emulator running Android 7.0, the icon still showed up on status bar (unfortunately all my live devices are on 8.0). What could be the way to achieve this on Android 7 and below?

BTW here is the code I used to set notification with no status bar icon for a foreground service:
B4X:
Sub Service_Create
    
    Dim nb As Notification
    nb.Initialize2(nb.IMPORTANCE_MIN)
    nb.Vibrate=False
    nb.Sound=False
    nb.Light=False
    nb.Icon="icon"
    
    nb.SetInfo("Test","Testing","")
    
    Service.AutomaticForegroundNotification=nb
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
    
End Sub
 

Inman

Well-Known Member
Licensed User
Longtime User
Thank you Erel. I checked the documentation and noticed IMPORTANCE_NONE. Unlike IMPORTANCE_MIN, they don't say anything explicitly about using it on foreground services.

I tried it out on Android 8.x devices and it completely hides notification icon while the service is running. But on Android 7 emulator it still shows the full size icon all the time.

There is an app called GSam Battery Monitor that successfully hides its notification icon on both Android 7 and 8 (while still having the notification which can be seen only on pulldown) while the service is still running. Not sure if its targetSDK is 26 but it has been giving the user an option to hide the notification icon for a while now. I tested it on the same emulator running Android 7 and it does hide the notification icon until pulldown.

Any idea how it does this?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
That is a very interesting idea. And it works as transparent icon means there is nothing visible on status bar per say. But the downside is that, when the user pulls down the notification shade, he will see a notification with title, message and everything except the icon, which looks a bit awkward. Nevertheless it works.

But I still believe there is a better way to do this. I am attaching 2 screenshots from the open source ad blocker called Blokada. It's minSDK is 21 and targetSDK is 27 and so it is compiled for Oreo. Both screenshots have been taken while Blokada is running.

In the first image, if you look at the statusbar at the top, you can see that there is no notification icon related to Blokada; only the usual icons such as WiFi, Bluetooth etc... Now this can be achieved by using a transparent icon for notification. But if you check the second image, you can see the Blokada notification running. And what is interesting is that in the first line of notification that says "Blokada . now", you can see its icon to the left. If you use a transparent icon, that icon on the left will be a blank space. But somehow Blokada is able to do both.

And this is what I am trying to achieve.

9pyiabO.jpg
zfRU3eu.jpg
 
Upvote 0
Top