I can list paired Bluetooth devices, and I need to check their current connection status when the application starts.
But I did not find a way to get the connection status ?!
Here are some attempts I tried but failed:
- android.bluetooth.BluetoothDevice
It has a way to get the communication status of the remote device, and the possible values ββfor the communication status are: BOND_NONE , BOND_BONDING , BOND_BONDED . But this is not a connection state.
- android.bluetooth.BluetoothProfile
This method can be used to get the connection status, but the BluetoothProfile object must first be received.
public abstract int getConnectionState (BluetoothDevice device);
As described in the document: "Clients must call getProfileProxy (Context, BluetoothProfile.ServiceListener, int) to get a proxy proxy.", It can ONLY be retrieved into the ServiceListener when the state changes.
What if I request a state at startup without any state changes?
- android.bluetooth.BluetoothManager
It provides a method:
public int getConnectionState (BluetoothDevice device, int profile);
But it cannot be used to determine the connection status of the Bluetooth speaker, since the profile argument accepts only GATT or GATT_SERVER (for a low-energy device), other profiles ( HEADSET , HEALTH , A2DP ) are not supported.
- android.bluetooth.BluetoothAdapter
It provides a method:
public int getProfileConnectionState (int profile);
This function can be used to check if the local Bluetooth adapter is connected to any remote device for a specific profile. It can be used to verify a given profile. But it cannot be used to test this device.
Does anyone know how to get the connection status of this Bluetooth ?
Thanks in advance.
android bluetooth
Raymond xie
source share