Status bar expand and hide

mc73

Well-Known Member
Licensed User
Longtime User
Hello, found this:
B4X:
Object service  = getSystemService("statusbar");   Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");   Method expand = statusbarManager.getMethod("expand");   expand.invoke(service);

Haven't get into the reflector yet, so perhaps anyone can provide the correct syntax?
It would be a nice getting-started for me, thank you :)
 

mc73

Well-Known Member
Licensed User
Longtime User
You can hide it by choosing Project - Activity properties - full screen.

Do you need to do it at runtime?
yes i want it as part of a kiosk mode app. i done want the status bar hidden. i need it collapse when user tries to expand it.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
What OS/Version of Android are you running? Are you talking about the Activity title bar or the OS status bar?

The OS.

I don't want it to get hidden, I like it staying to where it is. I just don't like users messing around with it, you know, turning wifi on/off, and so on :)
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I've seen it happening in a kiosk app. When user tries to expand the bar, it gets back to its original position. I've seen it in 2.3 and ICS. I can be sure it uses either a permission to read its status, or uses a trick to get its position. Then I see the status bar collapsing. It's really cool for occasions like the one I've described.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Ok, don't know if this is the correct way to use reflection but seemed to work for me on android 2.3.
B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    Dim tmr As Timer 
    Dim cmd As Button 
    Dim intrv As Int 
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    ' we need this to the manifest
    ' AddPermission(android.permission.EXPAND_STATUS_BAR)
    
    cmd.Initialize ("cmd")
    cmd.Text="Expand for some secs"
    Activity.AddView (cmd,20%x,30%y,60%x,40%y)
    tmr.Initialize ("tmr",100)
    tmr.Enabled =True
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub cmd_click

    expandCollapseStatusBar (True)

End Sub

Sub tmr_tick
    If intrv<1 Then 
        expandCollapseStatusBar(False)
    Else
        intrv=intrv-1
    End If
End Sub

Sub expandCollapseStatusBar(choice As Boolean )

    Dim r As Reflector 
    r.Target =r.GetContext 
    r.target=r.RunMethod2("getSystemService","statusbar","java.lang.String")
    If choice Then
        intrv=100
        r.RunMethod ("expand")
    Else
        r.RunMethod ("collapse")
    End If
End Sub
Of course, I cannot rely on running this inside an activity, I will prefer to use my service.
 
Upvote 0

massi636

New Member
Licensed User
Longtime User
B4X:
Sub expandCollapseStatusBar(choice As Boolean )

    Dim r As Reflector 
    r.Target =r.GetContext 
    r.target=r.RunMethod2("getSystemService","statusbar","java.lang.String")
    If choice Then
        intrv=100
        r.RunMethod ("expandNotificationsPanel")
    Else
        r.RunMethod ("collapsePanels")
    End If
   
End Sub

For 4.2.2; but it doesn't work on my nexus 7...:BangHead:
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I think that in more recent android's versions, the method's name has changed. I will surely have a look and report back if in the mean time you don't find the appropriate way.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
B4X:
Sub expandCollapseStatusBar(choice As Boolean )

    Dim r As Reflector 
    r.Target =r.GetContext 
    r.target=r.RunMethod2("getSystemService","statusbar","java.lang.String")
    If choice Then
        intrv=100
        r.RunMethod ("expandNotificationsPanel")
    Else
        r.RunMethod ("collapsePanels")
    End If
   
End Sub

For 4.2.2; but it doesn't work on my nexus 7...:BangHead:

There's a function undocumented for 4.2.2: expandSettingsPanel
 
Upvote 0
Top