I'm a beginner in android app development. I've tried reading the documentation but am getting nowhere (functions in Android's tutorial such as StartLeScan()
have been deprecated, etc...)
Is there a simple function that returns a list of bluetooth devices ?
something like getDevices()
-> (list of devices) ?
Thank you
if you are using api level less than 21 then you will find that StartLeScan has been deprecated, In android lollipop StartLeScan() has introduced with new scan settings feature. You can use below code to scan BLE devices.
basically it depends on which android version you are targeting. since the api has changed a bit in lollipop (21).
in your activity, get the bluetooth adapter
then you should check which android version you are targeting
dont forget to add permissions in your manifest
I also thought this problem for few hours and I found out the answer by searching the Official doc.
You need to know 3 class and method ScanCallback,BluetoothLeScanner,ScanResult
//my level is so low that I cannot post the link....
You can see in the android developer web ,the web page would show Added in API level 21" on the right side.
Here is my code , modified from these project
my grandle:
These code works well on my phone,which is API 21 Hope it help you.
I had been playing with BLE scan for a while until I got the simplest solution from Nordic library.
Add a line to your build.gradle:
And use BluetoothLeScannerCompat:
And the library does all job.