Android Code Snippet Disable access to the StatusBar (Notification bar)


Posting here because I have searched a long time before to find the solution. I am not an expert and without Erel's help, I wouldn't have been able to make this working.
So, please apologize if I won't be able to help greatly.

A sample project is attached. I have tested it from Android 2.3 to Android 5.0.2 (Nexus 7 2013).
The project includes the code that Erel kindly translated for us in b4a.

You will need to add those permissions into your Manifest

What does the code do ?
It adds a label at the top of the StatusBar. For debugging, I did use a sentence (check the Process_Globals in the service to modify its value).

Why do I put the code in a service ?
Because the system kills the activity, the label stays on top for some moment and the label disappears. Using a service and restarting it when it gets killed is the way I have found to keep it running.

Could I remove the overlay by code ?
Yes, please see the project Overlay-OnOff attached (thanks to DonManfred)

Can I start the service at boot time ?
Yes, check Service Attributes

#Region Code to disable access to the StatusBar
'Code translated by Erel:
'Original source code:
Sub AddOverlay
Dim mView As Label
    mView.Text = Sentence
    Dim mlp As JavaObject
    Dim vtype As Int = -1, pixelFormat As Int = -3
    mlp.InitializeNewInstance("android.view.WindowManager$LayoutParams", Array(vtype, 100, 2010,296, pixelFormat))
    mlp.SetField("gravity", Bit.OR(Gravity.TOP, Gravity.CENTER))
    Dim windowManager As JavaObject = GetContext.RunMethod("getSystemService", Array("window"))
    windowManager.RunMethod("addView", Array(mView, mlp))
End Sub

Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    Return jo.GetFieldJO("processBA")
End Sub
#End Region


    7.2 KB · Views: 867
    8.6 KB · Views: 950
Last edited:


Active Member
Licensed User
Longtime User
Hello to all
I tried this system on android 5 6 7 ok
android 8 does not work for me
the status bar is not hidden or a black bar appears above it
There's a chance that it works on android 8
Android: targetSdkVersion = 22 ?
Thanks in advance for an answer