react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

Can't disconnect from bluetooth device on android

Open Betapig1 opened this issue 2 years ago • 4 comments

Describe the bug After successfully connecting to my arduino device, calling BleManager.disconnect does not disconnect the app from the device. I am confirming this in 2 ways, by checking the logs on my arduino which I have confirmed will tell me when a device disconnects, as well as checking BleManager.getConnectedPeripherals

The disconnect is not throwing an error, from the functions point of view it is not having any issues (as in the catch block never runs) however no disconnection ever actually happens.

I've confirmed that the ID I'm sending in is the correct one, and if I sent in an ID that doesn't corrolate to any attatched devices it says "Peripheral not found"

Expected behavior Expected behaivor is for my device to fully disconnect from the bluetooth device when running BleManager.disconnect

Smartphone (please complete the following information):

  • Device: Galaxy Z Flip Original
  • OS: Android version 12
  • react-native-ble-manager version: 8.4.4, and 7.6.3
  • react-native version:0.70.5

Here is the code if that helps ` const disconnectBluetooth = async () => { console.log('DISCONNECTING', id); // manager.disconnect(id); await BleManager.disconnect(id) .then( async(results) => { // Success code console.log('Disconnected',results);

})
.catch(error => {
  // Failure code
  console.log(error);
});

var discovered = await BleManager.getConnectedPeripherals([])
console.log("got end", discovered[0])
 

};`

Betapig1 avatar Nov 17 '22 00:11 Betapig1

Hi ! I had this behavior too and fixed it after a long time of trial and error:

  1. don't use discoverPeripheral Event, it seems like it interfere with the connect method, use BleManager.getDiscoveredPeripherals method instead, AFTER(!!) stop scanning
  2. Be sure that you are not scanning!
  3. connect to device
  4. disconnect with force param set to falseBleManager.disconnect(<id>, false) on Android

Good luck :-)

jayjo34 avatar Jan 25 '23 10:01 jayjo34

I am also facing the same issue here on Android. It happens for multiple IoT devices that i am connecting to.

I have also tried all the solutions i can find but still does not resolve it. Anyone can shed some light, please?

zhifeng-heng avatar Jun 28 '23 05:06 zhifeng-heng

same issue, Help!!!!

E android.os.DeadObjectException at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(BinderProxy.java:550) at android.bluetooth.IBluetoothGatt$Stub$Proxy.clientDisconnect(IBluetoothGatt.java:1873) at android.bluetooth.BluetoothGatt.disconnect(BluetoothGatt.java:898) at it.innove.Peripheral.lambda$disconnect$3$it-innove-Peripheral(Peripheral.java:186) at it.innove.Peripheral$$ExternalSyntheticLambda14.run(Unknown Source:6) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7664) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

evan0204 avatar Aug 07 '23 15:08 evan0204

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

marcosinigaglia avatar Dec 10 '23 02:12 marcosinigaglia

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

marcosinigaglia avatar Mar 15 '24 01:03 marcosinigaglia