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.
Device discovery is a scanning procedure that searches the local area for Bluetooth-enabled devices and requests some information about each one.
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.
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.
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.
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