Sub getDeviceName(Index As Int, Descriptor As Boolean) As String
'Original function code by 'thedesolatesoul'
'https://www.b4x.com/android/forum/members/thedesolatesoul.11412/
Dim jo As JavaObject
jo.InitializeStatic("android.view.InputDevice")
Dim DeviceIds() As Int = jo.RunMethod("getDeviceIds", Null)
Dim Name(DeviceIds.Length - 1) As String
Dim Desc(DeviceIds.Length - 1) As String
Dim Device_Index = 0 As Int
For i = 0 To (DeviceIds.Length - 1)
Dim joDevice As JavaObject = jo.RunMethodJO("getDevice", Array As Object(DeviceIds(i)))
Dim sources As Int = joDevice.RunMethod("getSources", Null)
Log(sources)
If Bit.AND(sources, 1025) = 1025 OR Bit.AND(sources, 16777232) = 16777232 Then
Name(Device_Index) = joDevice.RunMethod("getName", Null)
Desc(Device_Index) = joDevice.RunMethod("getDescriptor" ,Null)
Log("Device Index: " & Device_Index & CRLF & _
"Name: " & Name(Device_Index) & CRLF & _
"Descriptor: " & Desc(Device_Index))
Device_Index = Device_Index + 1
End If
Next
If Name(Min(Index, Name.Length - 1)) <> "" Then
If Descriptor = True Then
Return Desc(Index)
Else
Return Name(Index)
End If
Else
Log("No Gamepad or Joystick detected.")
Return "No Gamepad or Joystick detected."
End If
End Sub