Request Bluetooth Permission on Android 12

Hi All!

Android 12 requires that you now explicitly request Bluetooth permissions rather than just requesting location. I can’t figure out how to request bluetooth permissions on android. More info below:

I’m using react-native-ble-plx and the new Expo plugin that allows you to use bluetooth without ejecting. On IOS it works perfectly and asks for bluetooth (nearby devices) access. On android it does not. Here is my app.json:

"plugins": ["expo-camera",["@config-plugins/react-native-ble-plx", {
  "isBackgroundEnabled": true
}]],
"android": {
  "package": "com.youareaccountable",
  "permissions": ["CAMERA", "android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH_CONNECT", "ACCESS_COARSE_LOCATION", "android.permission.BLUETOOTH_ADVERTISE", "BLUETOOTH_SCAN", "BLUETOOTH", "ACCESS_FINE_LOCATION"],
  "versionCode": 11
  
},

I also tried requesting the permissions as just “BLUETOOTH_SCAN” etc.

Thank you for any insight you have!

Hi @accountableapp

It looks like you can use react-native-permissions

Yes, but that doesn’t work in the managed workflow as far as I could tell. Trying to get this working within the managed workflow.

From the installation instructions it looks like it should work out of the box on Android as long as you build with EAS Build, which you’ll also need to do for the Bluetooth support.

When I had tried it, my iphone app would no longer load on the developer build and would crash on the internal build.

Okay figured it out! I needed to do the following:

  1. Upgrade from SDK 44 to 45 because RN .66 and higher have the new Android Permissions
  2. Import PermissionsAdnroid from “react-native”
  3. Request Permissions:
if (Platform.OS === "android") {
         // console.log(PermissionsAndroid.PERMISSIONS); 
          status = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN);  
         // console.log(status); 
          status = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT);
         // console.log(status); 
      }
  1. app.json:
    "plugins": ["expo-camera",["@config-plugins/react-native-ble-plx", {
      "isBackgroundEnabled": true
    }]],

  "android": {
      "package": "com.youareaccountable",
      "permissions": ["CAMERA", "BLUETOOTH_ADMIN", "BLUETOOTH_CONNECT", "ACCESS_COARSE_LOCATION", "BLUETOOTH_ADVERTISE", "BLUETOOTH_SCAN", "BLUETOOTH", "ACCESS_FINE_LOCATION"],
      "versionCode": 11
      
    },

Hopefully this saves someone a lot of time :slight_smile:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.