>Follwoing是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()
方法;但与经典设备不同的是,由于我们没有可以获取蓝牙低功耗设备的连接状态的方法,我们无法正确更新低功耗设备的连接状态。
可以在此处找到此类的完整源代码
任何帮助都非常感谢。
您正在使用的低功耗蓝牙开发套件是什么?
截至目前,Android还没有用于低功耗蓝牙设备的本机API。您可能必须使用第三方API,例如Broadcomm的BLE,TI或CSR。
http://code.google.com/p/broadcom-ble/
摩托罗拉蓝牙低功耗原料药http://developer.motorola.com/docs/bluetooth-low-energy-api/
您可以查看此页面,了解有关选择开发套件的更多信息。BTLE(低功耗蓝牙)开发套件 - 必须具有接近配置文件