Android Question distinguish if device has a notch or not?

Brandsum

Well-Known Member
Licensed User
folllowing https://www.b4x.com/android/forum/threads/immersive-mode-with-notch-area-support.100636/

How one can distinguish if the device has a notch or not to chose the right procedure for the display size?

B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext

Dim JO As JavaObject = ctxt.RunMethodJO("getWindow", Null)
JO = JO.RunMethodJO("getDecorView", Null)
JO = JO.RunMethodJO("getRootWindowInsets",Null)
JO = JO.RunMethodJO("getDisplayCutout",Null)

If JO.IsInitialized Then
    Log("Device has a notch")
    JO = JO.RunMethodJO("getSafeInsetTop",Null)
    Log("Notch Height: " & JO)
End If

Check this documentation for more details: https://developer.android.com/reference/android/view/DisplayCutout
 
Upvote 0

capisx

Member
Licensed User
Longtime User
B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext

Dim JO As JavaObject = ctxt.RunMethodJO("getWindow", Null)
JO = JO.RunMethodJO("getDecorView", Null)
JO = JO.RunMethodJO("getRootWindowInsets",Null)
JO = JO.RunMethodJO("getDisplayCutout",Null)

If JO.IsInitialized Then
    Log("Device has a notch")
    JO = JO.RunMethodJO("getSafeInsetTop",Null)
    Log("Notch Height: " & JO)
End If

Check this documentation for more details: https://developer.android.com/reference/android/view/DisplayCutout

I've tried this code but the "JO" always return 'Not initialized', tested both in emulator and phone with notch.
 
Upvote 0
Top