Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BluetoothAdapter.startScan() vs BluetoothAdapter.startLeScan()

my goal is to find nearby Bluetooth devices(LE devices and "Classic"), in order to associate between current visible nearby devices to some functionality my app doing with it. (not a specific device/devices, but all of them!!!)

what I know:

  • startLeScan() would callback only with BLE devices
  • the two methods working in different way - while startBLeScan() managed by my code with callbacks while classic scan is managed by the system process, and returns the BluetoothDevice found via broadcasts.

what I don't know for sure:

  • assuming current device API level is 18+ startScan() will find always both discoverable BLE and classic devices.
  • BluetoothDevice.connectGatt() added with the new BLE API's, but should work also with classic bluetooth(return GATT Services...).

what I would like to know:

  • if indeed startScan() returns both types (Classic and BLE), what would be better to use in terms of battery consumption, performances, good practices and other aspects?

my application will perform background scans periodically, so I would like to minimize the battery consumption impact as possible.

like image 640
Tal Kanel Avatar asked Feb 16 '14 10:02

Tal Kanel


People also ask

How do you check Bluetooth is on or off in android programmatically?

Call isEnabled() to check whether Bluetooth is currently enabled. If this method returns false, then Bluetooth is disabled. To request that Bluetooth be enabled, call startActivityForResult() , passing in an ACTION_REQUEST_ENABLE intent action.

Where do we use Extra_discoverable_duration?

It allows remote devices to see this Bluetooth adapter when they perform a discovery. For privacy, Android is not discoverable by default. The sender of this Intent can optionally use extra field EXTRA_DISCOVERABLE_DURATION to request the duration of discoverability.

How do I get a list of Bluetooth devices on my Android phone?

By using BluetoothAdapter method getBondedDevices(), we can get the Bluetooth paired devices list. Following is the code snippet to get all paired devices with name and MAC address of each device.

How do I find my Bluetooth UUID Android?

Set<BluetoothDevice> devices = BluetoothAdapter. getDefaultAdapter(). getBondedDevices(); BluetoothDevice glass = null; for (BluetoothDevice d : devices { ParcelUuid[] uuids = d. getUuids(); for (ParcelUuid p : uuids) { System.


2 Answers

You have to start a scan for Classic Bluetooth devices with startDiscovery() and a scan for Bluetooth LE devices with startLeScan(). Caution: Performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources.

Edit: On LG Nexus 4 with Android 4.4.2 startDiscovery() finds Bluetooth LE devices. On Samsung Galaxy S3 with Android 4.3 startDiscovery() doesn't find Bluetooth LE devices.

like image 177
Andrea Motto Avatar answered Oct 26 '22 19:10

Andrea Motto


I have an off-market Chinese tablet that has BLE support, however, it always return a BLE equipped device with its name as "null" when I call startLeScan. The issue was resolved by calling startDiscovery. Remember that if your app targets 23 or above, you will need to have location permissions for startDiscovery to work correctly. Hope it helps.

like image 26
redlee90 Avatar answered Oct 26 '22 17:10

redlee90