How to detect if the bluetooth device is out of range or we have lost it?
For the detected bluetooth device, we get Brodcast from Android with action:
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// New bluetooth device found
}
When we set up a detection device, then this happens.
My question is what are the intents that are triggered when device discovery is disabled or the bluetooth of another device is disabled.
In my list view, I am showing devices that are "FOUND", I can do this using the code above. But I want to delete the entry of a device that is no longer in range, is no longer discoverable, or turns off Bluetooth, is there any specific intent the android platform is launching?
I have looked BluetoothDevice
, BluetoothAdapter
link API
s. But no useful broadcast action was found.
source to share
The target you are looking for is BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED
The destination used to translate the change in connection state of the local Bluetooth adapter to the profile of the remote device.
This intent will have 3 additions:
-
EXTRA_CONNECTION_STATE
- Current connection status. -
EXTRA_PREVIOUS_CONNECTION_STATE
- previous connection state. - EXTRA_DEVICE - remote device.
EXTRA_CONNECTION_STATE
or EXTRA_PREVIOUS_CONNECTION_STATE
maybe
source to share