Follwoing is the code android uses to get the connection summary(to display the connection status labels)
private int getConnectionSummary() {
...........................
...........................
for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) {
int connectionStatus = cachedDevice.getProfileConnectionState(profile);
switch (connectionStatus) {
case BluetoothProfile.STATE_CONNECTING:
case BluetoothProfile.STATE_DISCONNECTING:
return Utils.getConnectionStateSummary(connectionStatus);
case BluetoothProfile.STATE_CONNECTED:
profileConnected = true;
break;
case BluetoothProfile.STATE_DISCONNECTED:
if (profile.isProfileReady()) {
if (profile instanceof A2dpProfile) {
a2dpNotConnected = true;
} else if (profile instanceof HeadsetProfile) {
headsetNotConnected = true;
}
}
break;
}
}
As you can see from the code above, they obtain the connection status for a Classic device using the following line of code:
int connectionStatus = cachedDevice.getProfileConnectionState(profile);
The android system calls the getConnectionSummary()
method irrespective of whether a Classic or Bluetooth Low energy device is trying to connect; but unlike a classic device, since we do not have a method by which we can get the connectionStatus for a bluetooth Low energy device, we are unable to update the connection status correctly for a Low energy device.
Full source for this class can be found here
Any help is much appreciated.