The android documentation states:
Note: You can only scan for Bluetooth LE devices or scan for Classic Bluetooth devices, as described in Bluetooth. You cannot scan for both Bluetooth LE and classic devices at the same time.
However I am noticing that calling mBtAdapter.startDiscovery(); is returning both classic and btle devices. Does anybody know what is correct here?
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.
Although Bluetooth Classic and BLE share some common components, they are not compatible. Rather, they work side by side. A BLE radio can't connect to a Bluetooth radio unless that Bluetooth radio supports BLE (called Dual Mode).
Device discovery is a scanning procedure that searches the local area for Bluetooth-enabled devices and requests some information about each one. This process is sometimes referred to as discovering, inquiring, or scanning.
From my understanding what the documentation means is that you cannot have a startLeScan() and a startDiscovery() running at the same time. The reason might be that there is only one BluetoothAdapter object (the object that represents the local Bluetooth hardware) therefor it cannot do two different operations that use the BluetoothAdapter at the same time.(If someone knows anything different as to how it works in the background, let us know)
startLeScan() -> scans only for BLE devices
startDiscovery() -> discovers all Bluetooth devices, also it only scans for 12 seconds and this cannot be changed (have a read through the method description)
Note: After doing a startDiscovery() inquiry scan when a BT device is found you can get the device type to identify what each device is, For example:
int deviceType = device.getType();
if(deviceType == BluetoothDevice.DEVICE_TYPE_CLASSIC)
{
}
else if(deviceType == BluetoothDevice.DEVICE_TYPE_LE)
{
}
else if(deviceType == BluetoothDevice.DEVICE_TYPE_DUAL)
{
}
else if(deviceType == BluetoothDevice.DEVICE_TYPE_UNKNOWN)
{
}
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