My app scans and connects to BLE devices from a foreground service. I want to upgrade SDK and target Android 12 (targetSdkVersion 32
) and support older versions of Android.
Android 12 introduced changes regarding bluetooth permissions.
Since Android 12: BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT, and BLUETOOTH_SCAN permissions are runtime permissions.
- If your app doesn't use Bluetooth scan results to derive physical location, you can make a strong assertion that your app never uses the Bluetooth permissions to derive physical location. To do so, complete the following steps:
Add the
android:usesPermissionFlags
attribute to yourBLUETOOTH_SCAN
permission declaration, and set this attribute's value toneverForLocation
.
- If location isn't otherwise needed for your app, remove the
ACCESS_FINE_LOCATION
permission from your app's manifest.
<manifest>
<!-- Include "neverForLocation" only if you can strongly assert that
your app never derives physical location from Bluetooth scan results. -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
<!-- Not needed if you can strongly assert that your app never derives
physical location from Bluetooth scan results and doesn't need location
access for any other purpose. -->
<!--
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
-->
...
</manifest>
I understand that the app should not request for the location permissions when the app runs on Android 12. My questions are:
- What with older devices ? Should my app request for runtime location permissions when running on pre Android 12 ?
- What with
ACCESS_FINE_LOCATION
,ACCESS_COARSE_LOCATION
andACCESS_BACKGROUND_LOCATION
permissions presence in the Manifest ? - What with using bluetooth in a service? The Android documentation also says that if an app uses bluetooth in service then the app should request for
ACCESS_BACKGROUND_LOCATION
. Should the app request for the background location access permission or not ? I am confused.
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
. See my answer https://mcmap.net/q/932469/-android-12-bluetooth-permissions-confusion of a similar question. I hope could help. – Integrate