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,
)
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,
)