Location Needs to Be Enabled for Bluetooth Low Energy Scanning on Android 6.0

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

No, this is not a bug.

This issue was brought up to Google where they responded saying that this was the intended behavior and they won't fix it. They directed developers to this site where it points out that location permission is now needed for hardware identifier access. It is now the developer's responsibility to make their users aware of the requirement.

In the issue, however, it doesn't address why Location services (GPS, etc.) are required and it doesn't seem like they are going to revisit the issue to explain this since it has been marked as the intended behavior.

To answer the second part of the question: Yes, it is possible to scan without enabling Location services. You can do a Bluetooth classic scan using BluetoothAdapter.getDefaultAdapter().startDiscovery() and that will work with Location services off. This will discover all Bluetooth devices, BLE and otherwise. However, BLE devices won't have a scan record that they would have had if they were seen as a result of startScan().

Should I request for location permissions when using bluetooth for pre Android 12 devices when targeting Android 12 (targetSdkVersion 32)

Ad 1. Should my app request for the runtime location permissions when running on pre Android 12 ?

Yes. The app should request for the runtime location permissions when running on pre Android 12

Ad 2. What with ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION and ACCESS_BACKGROUND_LOCATION permissions presence in the Manifest ?

These entries should be present in the Manifest. Additionally mark them using android:maxSdkVersion.
The manifest should resemble:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package.com">
<!-- https://developer.android.com/guide/topics/connectivity/bluetooth/permissions -->
...
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30"/>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
android:maxSdkVersion="30"/>

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
...
</manifest>

Ad 3. Should the app request for the ACCESS_BACKGROUND_LOCATION permission when uses bluetooth from a foreground service ?

Yes. The app should request for it.

Depending on the Android version, the app should request for:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
//`BLUETOOTH_SCAN` and `BLUETOOTH_CONNECT` on Android 12 and newer
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//`ACCESS_FINE_LOCATION` and `ACCESS_BACKGROUND_LOCATION` on Android 10..<12
} else {
//`ACCESS_COARSE_LOCATION` on Android 6..<10
}

Is it require to have location permission and Location service enabled to connect to BLE device via MAC ID

No it's not required, but please see https://stackoverflow.com/a/57099437/556495 why you can't always connect using only the Bluetooth Device Address.

Location requirement to scan for BLE devices

Q: Why has this been done by Google?

A: Because BLE scanning is commonly used to determine a user's location with Bluetooth LE beacons.

I discussed this with Google engineers at a Q&A session at Google I/O 2015 when the change was still not released. At the time, my concern was having to ask for Bluetooth LE Admin permissions to scan for location beacons. For me, this was a problem because users understood that my app needed to find a user's location, but did not understand why it needed to administer Bluetooth.

The engineers' response was that location permission (and location on) would be needed to do this in Android M to make this clearer to users. Unfortunately, from my perspective Bluetooth Admin permission is still required for historical reasons.

You can certainly disagree with Google's decision. But the reasoning is clear. If an app can scan for Bluetooth devices and can read their MAC addresses or other identifiers, it can also determine a user's location if the app developer knows where some of these scanned devices are located.

Why the same location permission logic does not apply to scanning WiFi or Bluetooth Classic (both of which would allow the same thing) is less clear. Perhaps it is just that Google was preparing to join the Bluetooth LE beacon game with their Eddystone standard.

Correction: Location permission is required for WiFi scans.



Related Topics



Leave a reply



Submit