kenjdavidson / react-native-bluetooth-classic

⚛ Bluetooth classic Android(Bluetooth)/IOS(ExternalAccessory) module for serial communication
https://kenjdavidson.github.io/react-native-bluetooth-classic
MIT License
249 stars 93 forks source link

scan and connect pemrissions #269

Closed ghost closed 1 year ago

ghost commented 1 year ago

Mobile Device Environment EXPO EAS

Is your feature request related to a problem? Please describe. SCAN and CONNECT permissions

Describe the solution you'd like tried this configuration ``` Expo Installation

Install react-native-bluetooth-classic and with-rn-bluetooth-classic (for auto-configuration of permissions and protocols) from npm with expo install:

expo install react-native-bluetooth-classic with-rn-bluetooth-classic

Configure app.json or app.config.json with the following:

"plugins": [ ["with-bluetooth-classic", { "peripheralUsageDescription": "Allow myDevice to check bluetooth peripheral info", "alwaysUsageDescription": "Allow myDevice to always use bluetooth info", "protocols": [ "com.myCompany.p1", "com.myCompany.p2" ] } ] ] ``` and many other app.json and in code androidPermission request and it still not asking for permissions

Describe alternatives you've considered Could be another library, but by far this is the most conveniesnt Additional context Please provide example or decent configuration for bluetooth scan and connect pemrissions

woflmao commented 1 year ago

Hey are you still stuck on this? I have a function in my project that looks like this:


  const requestAndroidPermissions = async () => {
    const bluetoothScanPermission = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN
    );
    const bluetoothConnectPermission = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT
    );
    const fineLocationPermission = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
    );
    return (
      fineLocationPermission === "granted" &&
      bluetoothScanPermission === "granted" &&
      bluetoothConnectPermission === "granted"
    );
  };

if you put this in a useEffect and keep track of the response via context or some other method it should (tm) work.