Android Question ImmersiveMode Using B4A [RESOLVED]

Big Dave

Member
Licensed User
Longtime User
I have been trying to use the Immersive mode...https://www.b4x.com/android/forum/threads/immersive-mode-hide-system-bars.161680/ but still have a missing library issue.

For context I have copied an app to a new more up to date device, the app originally written using B4A, not B4XPages. I have tried to follow the example in the thread above but still have a missing library issue on the "Dim immersive As ImmersiveMode" line. I have copied the jar and xml files to my Add Library folder but it is not showing in the Library list. Also I have no idea what to do with the B4X Mainfest (App Compatibility) code detailed in the thread.

All pointers and help very much appreciated.
 

Big Dave

Member
Licensed User
Longtime User
did you refresh the list?
Didn't realise you had to do that. Closed the project and B4A and then reopened and ImmersiveMode is now in the list. TYVM for that.

Can you enlighten me as to the purpose of the B4X Manifest (app compatibility), do I need to include it as the app is B4A not B4XPages.
 
Upvote 0

Big Dave

Member
Licensed User
Longtime User
App is now failing on..
B4X:
Sub Activity_WindowFocusChanged(HasFocus As Boolean)

    If HasFocus Then
        imImmersive.SetMode(imImmersive.SYSTEM_UI_FLAG_FULLSCREEN)
    End If
   
End Sub

With a null pointer error on the "Sub Activity..." line

java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA b4a.konnqa3.main.activityBA' on a null object reference in method 'java.lang.String b4a.konnqa3.main._activity_windowfocuschanged(boolean)'

I suspect I am missing something?

Thanks in advance.
 
Upvote 0

Big Dave

Member
Licensed User
Longtime User
You shouldn't try it in debug mode; try it in release mode.
Tried in Release mode and still getting an error

** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
main_activity_windowfocuschanged (java line: 727)
java.lang.NullPointerException: Attempt to read from field 'b4a.claude.immersive.immersivemode b4a.konnqa3.main._imimmersive' on a null object reference in method 'java.lang.String b4a.konnqa3.main._activity_windowfocuschanged(boolean)'
at b4a.konnqa3.main._activity_windowfocuschanged(main.java:727)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at b4a.konnqa3.main.onWindowFocusChanged(main.java:186)
at com.android.internal.policy.DecorView.onWindowFocusChanged(DecorView.java:2430)
at android.view.View.dispatchWindowFocusChanged(View.java:17541)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1542)
at android.view.ViewRootImpl.dispatchFocusEvent(ViewRootImpl.java:5958)
at android.view.ViewRootImpl.handleWindowFocusChanged(ViewRootImpl.java:5841)
at android.view.ViewRootImpl.-$$Nest$mhandleWindowFocusChanged(Unknown Source:0)
at android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl(ViewRootImpl.java:8391)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:8301)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loopOnce(Looper.java:273)
at android.os.Looper.loop(Looper.java:363)
at android.app.ActivityThread.main(ActivityThread.java:10060)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
java.lang.NullPointerException: Attempt to read from field 'b4a.claude.immersive.immersivemode b4a.konnqa3.main._imimmersive' on a null object reference in method 'java.lang.String b4a.konnqa3.main._activity_windowfocuschanged(boolean)'
sending message to waiting queue (OnActivityResult)
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Tried in Release mode and still getting an error

I use this code, and it works for me.

B4X:
Private Sub Activity_WindowFocusChanged(HasFocus As Boolean)
'    Log(HasFocus)
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(100) '(300)
            If GetSDKversion >= 36 Then
                jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
            Else
                jo.RunMethod("setSystemUiVisibility", Array As Object(8192+16))
            End If
        Catch
            Log("error")
            'Log(LastException) 'This can cause another error
        End Try 'ignore
    End If
End Sub

Public Sub GetSDKversion() As Int
    Dim p As Phone
    Return p.SdkVersion
End Sub
 
Upvote 0

Big Dave

Member
Licensed User
Longtime User
I copied the code from the "ImmersiveMode" example earlier and it worked for me also. I think I was trying to find a resolution using two different solutions. Thank you for your assistance, very much appreciated.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…