Follwoing一个蓝牙低功耗设备的代码Android使用来获取连接摘要(以显示连接状态标签)如何获得连接状态,在Android的
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;
}
}
正如你可以从上面的代码中看到,他们获得使用以下代码行用于经典装置的连接状态:
int connectionStatus = cachedDevice.getProfileConnectionState(profile);
Android系统调用getConnectionSummary()
方法无关的经典或蓝牙低功耗设备是否正在尝试连接;但与传统设备不同,由于我们没有一种方法可以获取bluetooth低功耗设备的连接状态,因此我们无法正确更新低能耗设备的连接状态。
该类完整的源可以发现here
任何帮助深表感谢。
我已经有几个配置文件与供应商提供的jar实现。而且我知道何时连接配置文件,断开连接等。但是,尽管Android系统调用上述方法,但我没有办法找到BLE设备的连接状态,与传统设备的连接状态不同该方法。 – user1400538
您能否详细说明您的要求?为什么你需要使用这个功能?你可以尝试第三方API – m4n07