android - Bluetooth.ACTION_FOUND not registering -
i have bluetooth device.
if:
- they have paired , connected device
- it becomes unplugged
- then becomes plugged in
i auto-connect it. that's why i'm listening action_found.
my code simple. action_bond_state_changed , action_acl_disconnected work fine. unable action_found catch though. "intent received" log message never prints…
i feel missing simple. thanks!
public void registerreceiver() { if (buildconfig.debug) log.e(tag, "registering receiver"); intentfilter filter = new intentfilter(); filter.addaction(bluetoothdevice.action_bond_state_changed); filter.addaction(bluetoothdevice.action_found); filter.addaction(bluetoothdevice.action_acl_disconnected); mainactivity.registerreceiver(receiver, filter); } private final broadcastreceiver receiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string action = intent.getaction(); if (buildconfig.debug) log.e(tag, "intent received: " + string.valueof(action)); if (bluetoothdevice.action_bond_state_changed.equals(action)) { bluetoothdevice device = intent.getparcelableextra(bluetoothdevice.extra_device); // … stuff … } else if (bluetoothdevice.action_found.equals(action)) { autoconnectdevice(); } else if (bluetoothdevice.action_acl_disconnected.equals(action)) { disconnectdevice(); } } }; public void unregisterreceiver() { if (buildconfig.debug) log.e(tag, "unregistering receiver"); mainactivity.unregisterreceiver(receiver); }
i believe action_found event fires when running device discovery intent pair device another. not fire when paired device comes range. unfortunately, there not appear event case want.
your best bet start asyctask or thread when connection lost , try reconnect until successful or until hit arbitrary time limit , give up.
Comments
Post a Comment