Android Question Check Bluetooth device type before attempting pairing

Patrick Clark

Active Member
Licensed User
When I use the system bluetooth scan on my phone it returns a list of devices but also knows whether they are phones, printers, pcs etc.

Is there anyway to get this information before attempting a pair. I am using the BluetoothManager Class from Erel to get the list of visible devices
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Update to Serial v1.30: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.59340/#post-619906

With this update it is possible to get more information using JavaObject:
B4X:
Private Sub Admin_DeviceFound (Name As String, MacAddress As String)
   Log(Name & ":" & MacAddress)
   Dim nm As NameAndMac
   nm.Name = Name
   nm.Mac = MacAddress
   foundDevices.Add(nm)

  'Code in DeviceFound
   Dim jo As JavaObject = admin
   jo = jo.GetField("LastDiscoveredDevice")
   Dim BClass As JavaObject = jo.RunMethod("getBluetoothClass", Null)
   Dim DeviceClass As Int = BClass.RunMethod("getDeviceClass", Null)
   Dim MajorDeviceClass As Int = BClass.RunMethod("getMajorDeviceClass", Null)

You can see the list of constants here: https://developer.android.com/reference/android/bluetooth/BluetoothClass.Device.Major (major)

And here:
https://developer.android.com/reference/android/bluetooth/BluetoothClass.Device (minor)
 
Upvote 0

Patrick Clark

Active Member
Licensed User
Excellent - Thanks Erel.

On a related but more complex note. Is it possible to send a query request from one to another to check my app is running on it or even have a device "advertise" that my app is running and then only discover them.

I'm not asking for a full answer but if you could point me in the right direction if anything is available.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top