Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth discover/scan code not working after update Android 6 on my Nexus 5

After the update (Android 6) my nexus 5, my running application not able to scan(find) the any bluetooth device. getBondedDevices() to get paired devices list working fine.

I have also test many sample code and application (I have put link below) of bluetooth functionality. all have the same problem, it's not able to find the bluetooth device.

But yes I have found only one application on play store which is working and it able to discover/scan the bluetooth device.

Not working apps on Android 6 (Nexus 5) I have tested many app like, bluetrem, sample code by Android Developer and many more.

Working app Bluetooth 4.0 Scanner https://play.google.com/store/apps/details?id=com.bluemotionlabs.bluescan

Is Any one know what is the problem, is there any changes required on code to make compatible with Android 6

like image 969
Mandy Avatar asked Dec 25 '22 13:12

Mandy


2 Answers

At least in Android 6.0 November 1, 2015 security patch, you not only need ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions but also need the location service actually turned on in order for Bluetooth scan to work.

I verified this in my app and a bunch of other BLE apps in Play Store, including Bluetooth 4.0 Scanner.

This means we have to make sure location is on before starting a scan, otherwise it will fail silently.

like image 181
Arrix Avatar answered Jan 30 '23 20:01

Arrix


It works, this is a solution, try to turn on GPS after put ACCESS_FILE_LOCATION or ACCESS_COARSE_LOCATION and after ask the runtime permission

like image 25
Tr4K4r Avatar answered Jan 30 '23 21:01

Tr4K4r