Android Question Permanently Hide Navigation and Status bars

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone, I'm developing a Kiosk App.
I set the app to go in Immersive Mode, however it is still possible for the user to show the android navigation and status bars… since it must be a kiosk app I do not want to have any android UI in it... is it possible to permanently hide the navigation and status bar while executing my app?

Thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
This link explains why: https://developer.android.com/design/ui/mobile/guides/layout-and-content/immersive-content

However, you can gain more control over the consequence of the user swiping to get out of immersive.
Using the example in Immersive Mode

In Main add this
B4X:
'In Process_Globals add
'    Private lostImmersion As Boolean

Sub Activity_Touch(action As Int, X As Float, Y As Float)
    If action = 1 And lostImmersion = True Then Swipe
    If lostImmersion Then Return
    If action = 2 And  Y < 100 Or Y > Activity.Height - 100 Then lostImmersion = True
End Sub

Sub Swipe
    B4XPages.MainPage.Swipe
    lostImmersion = False
End Sub

In B4XMainPage add
B4X:
Public Sub Swipe
    Dim sf As Object = xui.Msgbox2Async("Leave App?", "Warning", "Yes", "", "No", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        ExitApplication
    End If
End Sub

By the time the user responds, the Activity is back in immersive!
And the principle of User control is maintained.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
This link explains why: https://developer.android.com/design/ui/mobile/guides/layout-and-content/immersive-content

However, you can gain more control over the consequence of the user swiping to get out of immersive.
Using the example in Immersive Mode

In Main add this
B4X:
'In Process_Globals add
'    Private lostImmersion As Boolean

Sub Activity_Touch(action As Int, X As Float, Y As Float)
    If action = 1 And lostImmersion = True Then Swipe
    If lostImmersion Then Return
    If action = 2 And  Y < 100 Or Y > Activity.Height - 100 Then lostImmersion = True
End Sub

Sub Swipe
    B4XPages.MainPage.Swipe
    lostImmersion = False
End Sub

In B4XMainPage add
B4X:
Public Sub Swipe
    Dim sf As Object = xui.Msgbox2Async("Leave App?", "Warning", "Yes", "", "No", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        ExitApplication
    End If
End Sub

By the time the user responds, the Activity is back in immersive!
And the principle of User control is maintained.
Actually i'm looking for the opposite. While my app is shown I do not want the navigation bar and status bar to be visible, even if the user swipes-up
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Yes that's what this does. Start with the Immersion Example Immersive Mode. Modify as I showed.
It starts in immersive mode.

When the user swipes (top or bottom), it detects that and intercedes with a message.
That message could be anything. For example "don't do that" (not recommended) or what I suggested: an option to exit the App (since it is an immersive only App).

You'll see that the immersive mode is back by the time the user replies.

I have attached the example.
 

Attachments

  • ImmersPlus.zip
    14.6 KB · Views: 28
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Here are some alternative messages:

"Swiping from top or from bottom of screen has no effect in this App"
or
"This App will restart"
or
"Press Ok to continue"

Neither will give the user an opportunity to exit the App without powering off. Hopefully this is not their personal device

Use Wait For after the message invocation.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Yes that's what this does.
I already tried... the immersive mode works (I followed the tutorial I linked), but when I Swipe Up the navigation bar and status bar are temporary showed anyway and the same happens with your example, even if the msgbox is shown. (see attached image)

IMG_1162-min.jpg

Status bar seems to be gone only because there is a MsgBox showed... but I cannot use a MsgBox


Neither will give the user an opportunity to exit the App without powering off.
I already prevent the user to exit from the application by putting it in KIOSK MODE. The goal is not this, but is to NOT show any type of bar of Android, neither when swiping up, nothing must happen.


Hopefully this is not their personal device
No 😂, the app will run on a dedicated device
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
  • Never permanently hide system bars on personal devices. You cannot permanently hide system bars in your app unless for an Android Enterprise deployment, so your designs should account for them to provide the optimal experience. Read more about designing for system bars.
but I cannot use a MsgBox
Then the only solution seems to be an Android Enterprise deployment, which I know nothing about.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
By the way on my Tablet the status bars show only for a half second flash (a blink of the eye), before the message appears.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
For those still interested, there here is another fairly innocuous message that works to keep the App immersive.
Replace the Swipe sub in attachment #5 with
B4X:
Public Sub Swipe
    Dim jo As JavaObject = xui.Msgbox2Async("Please Wait", "", "", "", "", Null)
    Sleep(800)
    jo.RunMethod("cancel", Null)
End Sub

Or even

B4X:
Public Sub Swipe
    Dim jo As JavaObject = xui.Msgbox2Async("Not a valid swipe", "", "", "", "", Null)
    Sleep(200)
    jo.RunMethod("cancel", Null)
End Sub

Just being creative. If the theme color of MsgboxAsync is set to transparent, you can (untested) do this.
The only thing you'll see is a very brief flash of the navigation bar before it disappears.

B4X:
Public Sub Swipe
    Dim jo As JavaObject = xui.Msgbox2Async("", "", "", "", "", Null)
    Sleep(10)
    jo.RunMethod("cancel", Null)
End Sub
 
Upvote 0
Top