MacKentoch / react-native-beacons-manager

React-Native library for detecting beacons (iOS and Android)
MIT License
582 stars 316 forks source link

Error : App not detecting bluetooth on Android 12 #240

Open anhquanngo opened 2 years ago

anhquanngo commented 2 years ago

Version

1.0.7

Platform

Android

OS version

android 12.0...

Steps to reproduce

Use device with andrioid 12 Beacons do not appear in beaconDidRange event Expected behavior Beacons should be detected

Expected behavior

Beacons detected in all cases

Actual behavior

Beacons are not detecting in any case

Jake-Young commented 2 years ago

We recently ran into the same problem when building for Android 12 and above, given that Google are now expecting every new app to target Android 12 (31+). A number of things need changed to get this to work.

NOTE - These changes have only been tested on our side for ranging with iBeacons.

Now instead of BLUETOOTH and BLUETOOTH_ADMIN we now only need BLUETOOTH_SCAN.

So your permission for Bluetooth in you Android Manifest should look like:

<!-- Replace both of these -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!--  -->

<!-- With this -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<!--  -->

NOTE - You also need to change the required permissions in manifest for this library to the above. Again you only need BLUETOOTH_SCAN in the library manifest.

If you aren't already you also need to ask for both ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.

See permissions changes here: Android 12 Changes

We have forked this library to maintain it for more recent versions of RN, Android and iOS.

Our Fork: Here

If you don't want to use our fork, simply just update the permissions as I have described above and update the Altbeacon version to 2.19.4 as done here: https://github.com/MacKentoch/react-native-beacons-manager/pull/237

We know our version of the library works for RN up to:

  "react": "18.0.0",
  "react-native": "0.69.7",

I hope this solves your problems!

mattia-beta commented 1 year ago

It's working!

  "react": "17.0.2",
  "react-native": "0.65.3",
compileSdkVersion = 33
targetSdkVersion = 32
sangheraajit commented 1 year ago

Hi @mattia-beta

Do you have working code in android?

interstates21 commented 1 year ago

Worth to mention, BLUETOOTH_SCAN requires a runtime permission prompt. @Jake-Young's fork works perfectly in that case!