question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Beacon scanning not working with Android 12 Bluetooth permissions

See original GitHub issue

Hey David! Long time no see, I hope you’re doing well. 🙏

In the process of upgrading my application to Android 12, I was updating the permission declarations to the new Bluetooth permissions introduced in that OS version. Unfortunately, I’m unable to find my nearby beacon when using AltBeacon to range for it. Replacing the AltBeacon usage with some vanilla Android code (using BluetoothLeScannerdirectly), I did find it, however.

In the PR for Android 12, it was noted that scanning didn’t work unless ACCESS_FINE_LOCATION was also granted at runtime. Being a replacement for this old way, the new Bluetooth permissions should be able to work without that extra declaration though, so I went back into AltBeacon itself to see what I could find. Eventually, I landed inside this conditional inside CycledLeScanner, which I identified as the culprit. The permission check in this method does not take the new permissions into account. I believe that checkLocationPermission could be updated to include an SDK check and choose FINE/COARSE or the new BLUETOOTH_SCAN permission depending on the result. No problem from my end to file a PR for this change if it sounds good to you as well.

Expected behavior

Devices running Android 12 should be able to range for beacons without also requiring the old-style permissions.

Actual behavior

A declaration of ACCESS_FINE_LOCATION is required in order to make beacon ranging work, even on Android 12.

Steps to reproduce this behavior

Launch the reference application on an Android 12 device and try to find a nearby beacon with it.

Mobile device model and OS version

Pixel Pro 6, Android 12

Android Beacon Library version

2.19

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
davidgyoungcommented, Dec 2, 2022

My understanding is that it is not possible to detect popular bluetooth beacon formats (iBeacon, Eddystone) on when only approximate location permission is granted on Android 12+ because the operating system filters out those bluetooth detections. The operating system will only pass through those detections to third party apps if precise location permission is granted.

1reaction
davidgyoungcommented, Nov 15, 2021

Hi, Marcel.

Thank you for pointing out that line. At a minimum I think it should be changed to put a warning in the log in an else condition.

However, I am not sure it should be removed. In my tests of an app targeting Android 12 (See here: #1043), it is necessary to have both BLUETOOTH_SCAN and ACCESS_FINE_LOCATION in order to detect common beacon formats like iBeacon, AltBeacon and Eddystone. Android’s documentation says that the manifest must include one of these two:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
   android:usesPermissionFlags="neverForLocation" />

or

 <!-- Needed only if your app uses Bluetooth scan results to derive physical location. -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

And says:

Note: If you include neverForLocation in your android:usesPermissionFlags, some BLE beacons are filtered from the scan results.

See: https://developer.android.com/guide/topics/connectivity/bluetooth/permissions?hl=it_ch&skip_cache=false

Can you explain exactly what you have in your manifest and what kind of beacons you are scanning for? It sounds to me like what you describe is not supposed to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bluetooth permissions - Android Developers
If your app doesn't use Bluetooth scan results to derive physical location, you can make a strong assertion that your app never uses...
Read more >
Android 12 - Beacon scanning... weirdest thing - Stack Overflow
When I use the same exact code (from their sample app) in my app with exactly the same configuration and exactly the same...
Read more >
1296054 - Android 12 is not discovering advertisement data ...
Current guess from testing for this issue is that is connected to Android 12 Bluetooth permission change, as it is stated in documentation:...
Read more >
Android 12 apps won't ask for location permissions when all ...
This change breaks out Bluetooth scanning (and Bluetooth pairing) into its own separate permission by itself, free of the location permission ...
Read more >
Requesting permissions at runtime - Android Beacon Library
09-22 22:35:20.152 5158 5254 E BluetoothUtils: Permission denial: Need ACCESS_FINE_LOCATION to get scan results · <uses-permission android:name="android.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found