What I'm doing now is trying to scan for both BLE and classic bluetooth devices at the same time. As far as I could see I can discover both by using:
BluetoothAdapter.getDefaultAdapter().startDiscovery()
and receiving intents via previously registered BroadcastReceiver
. It works fine and I can distinguish between classic and LE devices but I have some valuable data in advertising packet and I have no idea how to get it from incoming Intent
. Appreciate any ideas.
Note: Android-powered devices are not discoverable by default. A user can make the device discoverable for a limited time through the system settings, or an app can request that the user enable discoverability without leaving the app.
1- If you want to search nearby Bluetooth devices, you must add BLUETOOTH_SCAN permission. 2- If you want your device to be discovered by other devices, you must add BLUETOOTH_ADVERTISE permission. 3- If you want your device to be communicable with other devices, you must add BLUETOOTH_CONNECT permission.
To find BLE devices, you use the startScan() method. This method takes a ScanCallback as a parameter. You must implement this callback, because that is how scan results are returned.
Swipe down from the top of the screen. Touch and hold Bluetooth . If your accessory is listed under "Available media devices," next to your device's name, tap Settings . If no accessories are listed under "Previously connected devices," tap See all.
I am not sure if this will allow you to get all the information you need, but it should allow you to get at least some of it.
When you receive the ACTION_FOUND
Intent
, that Intent
has an extra field identified by BluetoothDevice.EXTRA_DEVICE
. This extra contains an instance of BluetoothDevice
that represents the remote device. The BluetoothDevice
instance will allow you to get some information about the device such as its name and type.
Moreover, the ACTION_FOUND
Intent
also has an extra field identified by BluetoothDevice.EXTRA_CLASS
which contains a BluetoothClass
instance that also provides some more information about the remote device such as the class of the device.
See the class documentation for BluetoothDevice and BluetoothClass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With