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

Discussion in 'Android Questions' started by lemonisdead, Jan 10, 2015.

  1. lemonisdead

    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 :)
     
  2. lemonisdead

    lemonisdead Well-Known Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code to close the notifications screen:
    Code:
    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 likes this.
  4. lemonisdead

    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
     
  5. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Please guys, could you please, help me to translate this to b4a (source) ? Many thanks

    Code:
    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);
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    This is the code:
    Code:
    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, 1002010,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 likes this.
  7. lemonisdead

    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
     
    Peter Simpson likes this.
  8. lemonisdead

    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
     
    Cableguy likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice