AltBeacon / android-beacon-library

Allows Android apps to interact with BLE beacons
Apache License 2.0
2.83k stars 834 forks source link

Android 12 beacon not Scanning didRangeBeaconsInRegion beacon not detected with RxAndroidBle Gradle Add #1070

Closed mjkimloan closed 2 years ago

mjkimloan commented 2 years ago

Expected behavior

Add RxandroidBle to Gradle and beacon scan working

Actual behavior

but Add RxandroidBle to Gradle and beacon scan not working RxandroidBle All Version Same

override fun didRangeBeaconsInRegion(beacons: MutableCollection<Beacon>, region: Region) {
    Log.e(TAG, "Ranged: ${beacons.count()} beacons")
    Log.e(TAG, "Ranged: 0 beacons")
}

Mobile device model and OS version Galaxy S21 Android 12

Android Beacon Library version 2.19.3

Notice : RxAndroidBle version is 1.13.1 and Android 12 and lower versions scan beacons normally. Remove Rxandroidble from Gradle and beacons will scan normally. How can I solve this problem?

zahichemaly commented 2 years ago

I am facing the same issue. Were you able to solve this? Edit: I have an S21 FE, running Android 12.

davidgyoung commented 2 years ago

On Android 12, your app needs to obtain BLUETOOTH_SCAN permission or it will get the result described. See here

zahichemaly commented 2 years ago

The permission is already granted. RxAndroidBle is working fine, but the beacon is not being detected. Once I removed the RxAndroidBle from the gradle, I started detecting the beacon.

davidgyoung commented 2 years ago

You might try looking at your merged manifest when RxAndridBle is added to see if it makes changes that break your permissions setup. You can see instructions on inspecting manifest merging problems here https://developer.android.com/studio/build/manage-manifests

zahichemaly commented 2 years ago

Thanks a bunch. I found the issue. RxAndroidBle was using android:usesPermissionFlags="neverForLocation" which filters beacon discovery in the scan.

I added the following permission and explicitly removed the flag:

    <uses-permission
        android:name="android.permission.BLUETOOTH_SCAN"
        tools:remove="android:usesPermissionFlags"
        tools:targetApi="s" /> 
davidgyoung commented 2 years ago

Hey, Great, @zahichemaly. Glad to hear you found it.