Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Bluetooth Scan for classic AND BTLE Devices

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?

like image 283
EL45 Avatar asked Jul 31 '14 17:07

EL45


People also ask

How do I scan my Android phone for BLE?

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.

Can BLE connect with Bluetooth Classic?

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).

Can you scan for Bluetooth devices?

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.


1 Answers

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)
    {

    }
like image 177
KikiTheMonk Avatar answered Oct 06 '22 14:10

KikiTheMonk