[英]How to get connection states for a bluetooth low energy device in android
Follwoing is the code android uses to get the connection summary(to display the connection status labels) 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;
}
}
As you can see from the code above, they obtain the connection status for a Classic device using the following line of code: 从上面的代码中可以看到,它们使用以下代码行获取Classic设备的连接状态:
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; android系统会调用getConnectionSummary()
方法,而不管经典还是低功耗蓝牙设备都在尝试连接; 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. 但是与经典设备不同,由于没有一种方法可以获取蓝牙低能耗设备的connectionStatus,因此我们无法正确更新低能耗设备的连接状态。
Full source for this class can be found here 此类的完整资源可以在这里找到
Any help is much appreciated. 任何帮助深表感谢。
What is the Bluetooth Low energy development kit you are using ? 您正在使用什么蓝牙低功耗开发套件?
As of now Android doesn't have native API's for Bluetooth Low energy devices. 截至目前,Android还没有适用于低功耗蓝牙设备的本地API。 you may have to use third party APIs like the BLE From Broadcomm or TI or CSR. 您可能必须使用第三方API,例如Broadcom的BLE或TI或CSR。
http://code.google.com/p/broadcom-ble/ http://code.google.com/p/broadcom-ble/
Motorola bluetooth Low energy APIs http://developer.motorola.com/docs/bluetooth-low-energy-api/ 摩托罗拉蓝牙低能耗API http://developer.motorola.com/docs/bluetooth-low-energy-api/
You can look at this page for more information on selecting a Development Kit. 您可以在此页面上找到有关选择开发套件的更多信息。 BTLE (Bluetooth Low energy) development kit - must have proximity profile BTLE(蓝牙低能耗)开发套件-必须具有感应曲线
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.