Android Question Bluetooth device type

GaNdAlF89

Active Member
Licensed User
Longtime User
HI, I need to know the type of device connected (and discovering) via bluetooth. When I start the discover or I pair a bluetooth device in Android Bluetooth settings, along with the name of device, Android sets a specific icon based on device type: eg a printer icon if the device is a printer, a keyboard if it is a keyboard, etc. I need this exaclty type of device information. How can I do?
 

GaNdAlF89

Active Member
Licensed User
Longtime User
Hi @Erel, what I need is to access the BluetoothClass of the bluetooth device; exactly like here: https://stackoverflow.com/questions/29513987/determine-type-of-connected-bluetooth-device-in-android

My need: my app allows to connect bt printers and bt optical barcode readers. In phase of connection of a printer, I want to show to users only the paired devices (with method GetPairedDevices of a Serial object) that are printers, and the same thing with readers.
I need this, because users might not recognize a specific device (if a device is a printer or a reader) in bt paired devices list, when they want to connect it.
How can I do this?

Thanks to all!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code will extract all the required data from the paired devices:
B4X:
jo = jo.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethod("getDefaultAdapter", Null)
Dim PairedDevices() As Object = jo.RunMethodJO("getBondedDevices", Null).RunMethod("toArray", Null)
For Each pd As JavaObject In PairedDevices
   Log("*************")
   Log(pd.RunMethod("getName", Null))
   Log(pd.RunMethod("getAddress", Null))
   Log(pd.RunMethodJO("getBluetoothClass", Null).RunMethod("getDeviceClass", Null))
   Log(pd.RunMethodJO("getBluetoothClass", Null).RunMethod("getMajorDeviceClass", Null))
Next
 
Upvote 0

GaNdAlF89

Active Member
Licensed User
Longtime User
This code will extract all the required data from the paired devices:
B4X:
jo = jo.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethod("getDefaultAdapter", Null)
Dim PairedDevices() As Object = jo.RunMethodJO("getBondedDevices", Null).RunMethod("toArray", Null)
For Each pd As JavaObject In PairedDevices
   Log("*************")
   Log(pd.RunMethod("getName", Null))
   Log(pd.RunMethod("getAddress", Null))
   Log(pd.RunMethodJO("getBluetoothClass", Null).RunMethod("getDeviceClass", Null))
   Log(pd.RunMethodJO("getBluetoothClass", Null).RunMethod("getMajorDeviceClass", Null))
Next
Thank you very much! This is exactly what I needed.
 
Upvote 0
Top