Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location needs to be enabled for Bluetooth Low Energy Scanning on Android 10.0

After upgrading my Pixel XL to Android version 10.0 Bluetooth Low Energy (BLE) scanning will only work if i have Location turned on.

This has not been an issue until now and it's working on multiple devices running on Android 9.0, 8.0 and 6.0.1.

My app is only scanning in foreground using BluetoothLeScanner startScan(List<ScanFilter> filters, ScanSettings settings, ScanCallback callback)

My app has FINE_LOCATION, COARSE_LOCATION and BLUETOOTH permissions, I've tried adding ACCESS_BACKGROUND_LOCATION permission but had no luck.

Are there stricter requirements in Android 10.0 for apps to scan for Bluetooth devices, i can't find anything about this and am hoping i don't have to ask users to turn on Location for my app to work.

like image 894
GudniPall Avatar asked Oct 03 '19 13:10

GudniPall


People also ask

Why does Bluetooth low energy requires location?

Caution: BLE scanning typically needs location permissions as BLE scanning identifies objects that could be used for geolocation. Turning off location services will turn off Bluetooth scanning. From Android 12, apps that declare neverForLocation can gain Bluetooth scanning results even when location services are off.

How do I get permission to scan for Bluetooth?

1- If you want to search nearby Bluetooth devices, you must add BLUETOOTH_SCAN permission. 2- If you want your device to be discovered by other devices, you must add BLUETOOTH_ADVERTISE permission. 3- If you want your device to be communicable with other devices, you must add BLUETOOTH_CONNECT permission.

Does Bluetooth require location permission?

Target Android 12 or higher The CDM system provides a pairing UI on behalf of your app and doesn't require location permissions.


1 Answers

As of Android 10, it is now required to have ACCESS_FINE_LOCATION turned on in order to perform Bluetooth operations. The reason for this is that Bluetooth can be used to gather information about the location of the user (e.g. using BLE beacons), and for that the relevant app permission should be declared.

For Android 9 and lower, ACCESS_COARSE_LOCATION is sufficient which is probably why your app was working without an issue.

More information can be found here:-

  • https://developer.android.com/guide/topics/connectivity/bluetooth#Permissions
  • Bluetooth LE Scan doesn't work on Android M in the background

I hope this helps.

like image 189
Youssif Saeed Avatar answered Sep 20 '22 07:09

Youssif Saeed