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
250 stars 94 forks source link

getBondedDevices blocking the app #323

Closed Reyes2005 closed 4 months ago

Reyes2005 commented 5 months ago

The problem occurs when trying to use the getBondedDevices function, since executing it blocks the program and no button or state change works. The example code is the next:

const searchDevices = async () => {
      let bonded = await RNBluetoothClassic.getBondedDevices();
      setDevices(bonded);
      };
kenjdavidson commented 5 months ago

Can you provide more information on what "blocks the program" means? I, obivously, have an idea, but the code for this hasn't changed since the start of the library, and unless something changed on the Android or React Native side, it should be passing promises and handling threading appropriately between the two.

https://github.com/kenjdavidson/react-native-bluetooth-classic/blob/5c3be18b7a072faf299308be670a1f4fa02e7e28/android/src/main/java/kjd/reactnative/bluetooth/RNBluetoothClassicModule.java#L437

Shows the code, it is calling adapter.getBondedDevices

and looking at that

https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()

It should return back quickly, there are no notes stating that this method should be wrapped in a separate thread on the android side of things.

Is it possible that you're doing something else at the same time? Can you debug the android code and confirm that it is infact causing a long pause on that request?