I have job scheduler which searches BLE devices and connects in background. Android 10 introduced new ACCESS_BACKGROUND_LOCATION permission. Does ACCESS_BACKGROUND_LOCATION permission require to connection BLE device in background?
-
Does this answer your question? [Location needs to be enabled for Bluetooth Low Energy Scanning on Android 10.0](https://stackoverflow.com/questions/58220159/location-needs-to-be-enabled-for-bluetooth-low-energy-scanning-on-android-10-0) – Muhannad Fakhouri Mar 30 '20 at 10:52
-
My question is about background ble connection. – Pratik Popat Mar 30 '20 at 11:04
3 Answers
https://developer.android.com/guide/topics/connectivity/bluetooth#Permissions only mentions the app needs ACCESS_FINE_LOCATION
, so I suspect you don't need ACCESS_BACKGROUND_LOCATION
. But I see it likely this will be changed in the near future.
A quick look at https://android.googlesource.com/platform/packages/apps/Bluetooth/+/refs/tags/android-10.0.0_r32/src/com/android/bluetooth/gatt/GattService.java#1949 shows that only the fine permission seems to be needed, but I can have missed something.
I suggest you to simply try with only ACCESS_FINE_LOCATION
to see what happens in the background.

- 16,784
- 2
- 41
- 52
-
4If you try to scan for a device while in the background it just returns no devices. No errors or warnings. You need to explicitly request ACCESS_BACKGROUND_LOCATION then it works – Mitch Dart Oct 15 '20 at 13:04
I Think this article would help as it talks about location permission in android 11 and use of BLE.
also i would recommend you use Foreground services to give your user more insight on what your app is doing and allow them to determine if they need to give you app the permission once, or always.

- 1,649
- 1
- 19
- 24
Android documentation says:
If your app supports a service and can run on Android 10 (API level 29) or Android 11, you must also declare the ACCESS_BACKGROUND_LOCATION permission to discover Bluetooth devices. For more information on this requirement, see Access location in the background.
More information here: Android bluetooth permissions
So answer is: If you scan for devices or connect to them from service (even foreground service) you need to request for ACCESS_BACKGROUND_LOCATION permission.

- 445
- 6
- 18