Android Question Detection of navigation bar - Solved

padvou

Active Member
Licensed User
Longtime User
Hello,
I'm trying to detect if the android device has a navigation bar.
I found this code on the internet:
B4X:
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
How can this be run in B4A?

Or maybe someone has something better to suggest?
Thank you
 

padvou

Active Member
Licensed User
Longtime User
Thank you.
I also tried this:

B4X:
Sub GetRealWidth As Int
    Dim p As Phone
    If p.SdkVersion >= 17 Then
        Dim jo As JavaObject
        jo = jo.InitializeContext.RunMethodJO("getWindowManager", Null).RunMethod("getDefaultDisplay", Null)
        Dim metrics As JavaObject
        metrics.InitializeNewInstance("android.util.DisplayMetrics", Null)
        jo.RunMethod("getRealMetrics", Array(metrics))
        Return metrics.GetField("widthPixels")
    Else
        Return GetDeviceLayoutValues.Height
    End If
End Sub

Sub TESt
If GetRealWidth>GetDeviceLayoutValues.Width Then
'Uses nav bar
else
'Doesn't use nav bar
end if

end sub

Does it look like a correct approach?
 
Upvote 0
Top