Hello,
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
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
B4X:
AddPermission(android.permission.SYSTEM_OVERLAY_WINDOW)
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)
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
B4X:
#Region Code to disable access to the StatusBar
'Code translated by Erel:
'https://www.b4x.com/android/forum/threads/overlay-over-the-status_bar.49221/#post-309833
'Original source code:
'http://stackoverflow.com/questions/9815901/display-view-above-status-bar/25384365#25384365
Sub AddOverlay
Dim mView As Label
mView.Initialize("")
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)
jo.InitializeStatic(cls)
Return jo.GetFieldJO("processBA")
End Sub
#End Region
Attachments
Last edited: