Handling Bluetooth Disabling Gracefully
Is there a way to gracefully handle the toggling of Bluetooth from the phone while a connection is already established? I am able to register a broadcast receiver to handle the events STATE_TURNING_OFF and STATE_OFF. The Android API docs recommend gracefully disconnecting from any Bluetooth devices when the message STATE_TURNING_OFF is received, since the STATE_OFF message is not received until about 1-2 seconds (at least on my device) afterward. However, I'm unable to disconnect properly from the device in that time it seems. And I found that if I do not properly disconnect from the Metawear, then I cannot re-establish a connection without removing the battery. Any thoughts?
This discussion has been closed.
Comments
06-26 22:31:31.089 938-1948/? I/WindowState: WIN DEATH: Window{6e4cc82 u0 com.mbientlab.metawear.example/com.mbientlab.metawear.example.MainActivity}Again, I am assuming your Android device behaves differently wrt to Bluetooth connections?06-26 22:31:31.090 1100-1156/? D/BtGatt.GattService: Binder is dead - unregistering client (5)!
06-26 22:31:31.090 1100-1122/? D/BtGatt.AdvertiseManager: message : 1
06-26 22:31:31.091 1100-1122/? D/BtGatt.AdvertiseManager: stop advertise for client 5
06-26 22:31:31.092 1100-1122/? D/BtGatt.AdvertiseManager: app died - unregistering client : 5
06-26 22:31:31.092 1100-1118/? E/bt_btif: btgattc_handle_event invalid instance ID in BTIF_GATTC_DISABLE_ADV
06-26 22:31:31.092 1100-1122/? D/BtGatt.GattService: unregisterClient() - clientIf=5
06-26 22:31:31.093 1100-1145/? W/bt_btif: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
06-26 22:31:31.093 1100-1145/? W/bt_btif: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0016
06-26 22:31:31.093 1100-1145/? W/bt_btif: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0016
06-26 22:31:31.120 1100-1118/? D/BtGatt.GattService: onDisconnected() - clientIf=5, connId=5, address=D5:7B:B9:7D:CE:0E
06-26 22:31:31.120 1100-1118/? E/BtGatt.ContextMap: Context not found for ID 5
06-26 22:31:31.139 1100-1145/? I/bt_btm_sec: btm_sec_disconnected clearing pending flag handle:64 reason:22
06-26 22:31:31.140 1100-1118/? E/BluetoothRemoteDevices: state12newState1
06-26 22:31:31.145 28625-28625/? I/TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth disconnect broadast for MetaWear D5:7B:B9:7D:CE:0E
06-26 22:31:31.146 1100-1100/? D/BluetoothMapService: onReceive
06-26 22:31:31.146 1100-1100/? D/BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
06-26 22:31:31.154 28625-28625/? I/TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth disconnect broadast for MetaWear D5:7B:B9:7D:CE:0E