react-native-ble-manager
react-native-ble-manager copied to clipboard
Can't disconnect from bluetooth device on android
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])
};`
Hi ! I had this behavior too and fixed it after a long time of trial and error:
- don't use discoverPeripheral Event, it seems like it interfere with the connect method, use
BleManager.getDiscoveredPeripherals
method instead, AFTER(!!) stop scanning - Be sure that you are not scanning!
- connect to device
- disconnect with force param set to false
BleManager.disconnect(<id>, false)
on Android
Good luck :-)
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?
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)
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.
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.