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

[Android] [Crashed] App crashed after update the device setting #341

Open thnhat51202574 opened 18 hours ago

thnhat51202574 commented 18 hours ago

Mobile Device Environment Provide a list of operating systems on which this issue is relevant.

Application Environment Provide information about your development environment:

Describe the bug

To Reproduce

Screenshots Screenshot 2024-10-30 at 15 41 09

Additional context Add any other context about the problem here.

kenjdavidson commented 15 hours ago

Error looks like you need to add the BLUETOOTH_SCAN permission to the application. Is there something else that is showing up in the logs that leads you to believe this is not a configuration issue?

thnhat51202574 commented 9 hours ago

Hi @kenjdavidson, thank you for responding. These are the permissions we added to the AndroidManifest.xml:

<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" tools:targetApi="s" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

The issue never happens if the user accepts/allows the permission request. However, if the user opens the app for the first time (without taking any additional action) and then changes the device settings, we encounter a crash

kenjdavidson commented 9 hours ago

That sounds about right, there is information on the React Native site (and maybe these docs) saying that you need to manage that, you shouldn't be attempting to access anything without requesting permission. You should be able to handle that by wrapping all the bluetooth logic in a wrapper that checks if they've already give permission.

kenjdavidson commented 9 hours ago

https://kenjdavidson.com/react-native-bluetooth-classic/android/#android-permissions

If you feel like this needs more information, once you sort it out feel free to open a PR updating the docs for future users.

thnhat51202574 commented 1 hour ago

@kenjdavidson We have handled the permission request in our app, but it doesn't seem to be relevant. The issue occurs immediately after installing react-native-bluetooth-classic without adding any additional code.

The onHostDestroy function is registered in the Android codebase after running the yarn install command