Android Question [SOLVED] Overlay over the STATUS_BAR ???

lemonisdead

Well-Known Member
Licensed User
Hello,

Please, do you know how to create an overlay over the status bar ? I have found some code at StackOverflow that I am trying to convert to B4A but as I still don't get JavaObject & Reflection it is somehow hard : http://stackoverflow.com/a/25397029

The idea is to block access to the status bar and its settings. Many thanks for any help understanding how to do :)
 

Erel

Administrator
Staff member
Licensed User
You can use this code to close the notifications screen:
B4X:
Sub Activity_WindowFocusChanged(Focused As Boolean)
   If Not(Focused) Then CallSubDelayed(Me, "close")
End Sub

Sub Close
   Dim myPhone As Phone
   Dim i As Intent
   i.Initialize("android.intent.action.CLOSE_SYSTEM_DIALOGS", "")
   myPhone.SendBroadcastIntent(i)
End Sub
It is not 100% reliable.
 

lemonisdead

Well-Known Member
Licensed User
Thanks. Informatix gave me already a similar code. That's kind but is there a way to know when the status bar opens (to be able to close it in time) ? Thanks
 

lemonisdead

Well-Known Member
Licensed User
Please guys, could you please, help me to translate this to b4a (source) ? Many thanks

B4X:
mView=newTextView(this);
mView.setText(".........................................................................");

mLP =newWindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
100,
// Allows the view to be on top of the StatusBar
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
// Keeps the button presses from going to the background window
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// Enables the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);

mLP.gravity =Gravity.TOP|Gravity.CENTER;

mWindowManager =(WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mView, mLP);
 

Erel

Administrator
Staff member
Licensed User
This is the code:
B4X:
Dim mView As Label
   mView.Initialize("")
   mView.Text = "......................................................"
   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))
Doesn't seem to work on Android 5.
 

lemonisdead

Well-Known Member
Licensed User
Hello Erel,

I do thank you a lot for the conversion. I wouldn't had been able to do it myself (keeping it as an example to study as I am far away from really understanding things like you do).
I will post back an example if I manage to create the overlay with the help of your code. Thanks again
 

lemonisdead

Well-Known Member
Licensed User
Yeah : got it working and even on Android 5.0 (adding some permissions). I have posted the Code Snippet and a sample project here
 
Top