Dan Dascalescu
Dan Dascalescu

Reputation: 152036

How can an Android app pair with a BTLE device without requesting location permissions?

In order to scan for BTLE devices, an Android app needs ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. But does the app need to scan for BTLE devices in order to pair with one?

I'm seeing this specifically with an app that pairs with a sleep monitor and justifies it like this:

As of Android 6.0 Marshmallow, Android requires that apps performing Bluetooth Low Energy scans first ask for — and gain — permission to access a device’s Location Services.

For that reason, Sense will ask for permission to access Location Services during setup. In order to finish pairing Sense, you’ll need to grant access to Location Services.

Is this really necessary? How can they pair without requiring the user's location? I could already pair with the device independent of the app via the OS Bluetooth dialog.

Sense Bluetooth location why

Upvotes: 0

Views: 1122

Answers (1)

randdusing
randdusing

Reputation: 41

Technically if the BLE device is already paired with the mobile device, the app shouldn't even need to scan. Instead it can call this function to to get a list of devices that can be filtered by BLE: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getBondedDevices()

Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : devices) {
   if (device.getType() != BluetoothDevice.DEVICE_TYPE_LE) {
     continue;
   }
   //Do things to BLE device
}

But that doesn't allow me to filter by a UUID, which means I have to determine what the device is based on the address or name, both of which aren't reliable.

Upvotes: 1

Related Questions