react-native-bluetooth-classic icon indicating copy to clipboard operation
react-native-bluetooth-classic copied to clipboard

onDeviceConnected and onStateChanged are not working

Open learncodingforweb opened this issue 9 months ago • 1 comments

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

Device: Android 10
OS: API 29

Application Environment Provide information about your development environment:

React Native version: 0.78.0
RN Bluetooth Classic version: 1.73.0-rc.13

Describe the bug On connecting to bluetooth device using device.connect({ connectionType: 'binary' }), onDeviceConnected and onStateChanged are not called after successfull connection event i tried using RNBluetoothClassic.connectToDevice(address, { connectionType: 'binary' }). But i saw on diconnecting bluetooth device onDeviceDisconnected get called successfully

  useEffect(() => {
    const con_sub = RNBluetoothClassic.onDeviceConnected((event) => {
      console.log('onDeviceConnected', event);
      updateStatus('connect');
    });
    const dis_sub = RNBluetoothClassic.onDeviceDisconnected((event) => {
      console.log('onDeviceDisconnected');
      updateStatus('disconnect');
    });
    const state_sub = RNBluetoothClassic.onStateChanged((event) => {
      console.log('onStateChanged', event);
    });

    return ()=>{
      con_sub.remove()
      dis_sub.remove()
      state_sub.remove()
    }
  }, []);

Expected behavior on successfully connected to bluetooth device, it should call onDeviceConnected and onStateChanged.

learncodingforweb avatar Mar 13 '25 06:03 learncodingforweb