I have some Bluetooth devices that connect to my Android phone, however I am having problems detecting outages. Bluetooth devices do not send data packets if they do not need them, so you do not need to use a watchdog timer to receive packets to detect a disconnect. I read that you can use ACLDisconnected broadcast, but this event never fires for me (I waited for minutes). What is a reliable way to detect outages in Android 6?
Here is my AclDisconnect registration code:
_filter = new IntentFilter(); _filter.AddAction(BluetoothDevice.ActionFound); _filter.AddAction(BluetoothDevice.ActionBondStateChanged); _filter.AddAction(BluetoothAdapter.ActionDiscoveryStarted); _filter.AddAction(BluetoothDevice.ActionAclDisconnected); _filter.AddAction(BluetoothDevice.ActionAclDisconnectRequested); context.RegisterReceiver(_bluetoothDeviceReceiver, _filter);
And a callback (which does not work when disconnected)
public override void OnReceive(Context context, Intent intent) { string action = intent.Action; if (action == BluetoothDevice.ActionAclDisconnected || action == BluetoothDevice.ActionAclDisconnectRequested) { Interlocked.CompareExchange(ref Disconnected, null, null)?.Invoke(); } }
source share