Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in Bluetooth scanning and discovery on Android

There are two approaches defined in the Android to find out bluetooth devices. 1. Using bluetoothAdapter.startScan 2. bluetoothAdapter.discover

which approach is better.

2nd question, In onLeScan callback, how to check if scanning has been stopped.

like image 888
Manish Avatar asked May 13 '15 10:05

Manish


People also ask

What is Bluetooth scanning Android?

Device discovery is a scanning procedure that searches the local area for Bluetooth-enabled devices and requests some information about each one.

Can you scan using Bluetooth?

Bluetooth scanners are designed to connect wirelessly to a computer or other Bluetooth-enabled device. It then optically reads printed material and turns it into digital data. These scanners are used for a variety of purposes, including the scanning of images, text, and documents.


2 Answers

These methods apply to different versions of Bluetooth. Which one to use depends on what kind of device you have.

Classic Bluetooth uses BluetoothAdapter.startDiscovery() to find devices which are discoverable.

Bluetooth Low Energy support was added in API level 18, it uses BluetoothAdapter.startLeScan(ScanCallback). As of API level 21 this is replaced by BluetoothLeScanner.startScan().

See this samplecode on how to scan for LE devices. In onLeScan if you've found the device just call scanLeDevice(false);.

The onLeScan callback does not check if scanning has been stopped. You have to give the stopLeScan() command yourself.

like image 196
JPS Avatar answered Oct 17 '22 08:10

JPS


startScan() will be scanning for LE devices, startDiscovery() for normal bluetooth devices.

As far I know startLeScan() or startScan() will scan as long as method stopLeScan() or stopScan() will be called and you must call them.

like image 34
maciej Avatar answered Oct 17 '22 10:10

maciej