0

So I'm running into an issue where I am getting an app crashing on one phone (Pixel 6 Android 13), but not an Android 11 phone when running BLEManager.scan.

Here are the permissions being used:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

And in the app am running

PermissionsAndroid.request(
  PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
)

Guessing this is an android version issue, but not sure as this is not specified in docs.

Answer:

I needed to request these permissions at runtime post Android 12. I ran into issues because my version of react-native/@types/react-native was outdated and didn't contain the BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions. I bumped the version up past react-native@0.67 and then could request these permissions at runtime.

import { PermissionsAndroid } from "react-native"

await PermissionsAndroid.requestMultiple([
     PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
     PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
     PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
])

Previously I was only requesting

PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
)
Ben Rauzi
  • 564
  • 4
  • 13
  • 1
    Have you tried other Android 13 devices ? – Arti Feb 27 '23 at 10:05
  • 1
    For Android >= 12, the new Bluetooth permissions are permissions that must be requested at runtime. So similar to how older versions used the location permission. – Emil Feb 27 '23 at 11:55
  • Yep it was this, just there wasn't any updated documentation on this for the BLE Manager specifically. Thanks @Emil – Ben Rauzi Feb 27 '23 at 20:37

1 Answers1

0

Answer:

I needed to request these permissions at runtime post Android 12. I ran into issues because my version of react-native/@types/react-native was outdated and didn't contain the BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions. I bumped the version up past react-native@0.67 and then could request these permissions at runtime.

import { PermissionsAndroid } from "react-native"

await PermissionsAndroid.requestMultiple([
     PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
     PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
     PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
])

Previously I was only requesting

PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
)
Ben Rauzi
  • 564
  • 4
  • 13