Android Question detect hardware button exists or not

palmzac

Active Member
Licensed User
Longtime User
Hi,

How to detect hardware button exists or not ? ( like Menu Button ) Thanks !
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to check for the menu button:
B4X:
Sub HasPermanentMenuKey As Boolean
   Dim vc As JavaObject
   vc = vc.InitializeStatic("android.view.ViewConfiguration").RunMethod("get", Array(GetContext))
   Return vc.RunMethod("hasPermanentMenuKey", Null)
End Sub

Sub GetContext As JavaObject
  Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub
 
Upvote 0

palmzac

Active Member
Licensed User
Longtime User
Thanks Erel :)

You can use this code to check for the menu button:
B4X:
Sub HasPermanentMenuKey As Boolean
   Dim vc As JavaObject
   vc = vc.InitializeStatic("android.view.ViewConfiguration").RunMethod("get", Array(GetContext))
   Return vc.RunMethod("hasPermanentMenuKey", Null)
End Sub

Sub GetContext As JavaObject
  Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub
 
Upvote 0
Top