![](/img/trans.png)
[英]How to get connect with closest bluetooth low energy device from android ?
[英]How to get connection states for a bluetooth low energy device in android
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;
}
}
从上面的代码中可以看到,它们使用以下代码行获取Classic设备的连接状态:
int connectionStatus = cachedDevice.getProfileConnectionState(profile);
android系统会调用getConnectionSummary()
方法,而不管经典还是低功耗蓝牙设备都在尝试连接; 但是与经典设备不同,由于没有一种方法可以获取蓝牙低能耗设备的connectionStatus,因此我们无法正确更新低能耗设备的连接状态。
此类的完整资源可以在这里找到
任何帮助深表感谢。
您正在使用什么蓝牙低功耗开发套件?
截至目前,Android还没有适用于低功耗蓝牙设备的本地API。 您可能必须使用第三方API,例如Broadcom的BLE或TI或CSR。
http://code.google.com/p/broadcom-ble/
摩托罗拉蓝牙低能耗API http://developer.motorola.com/docs/bluetooth-low-energy-api/
您可以在此页面上找到有关选择开发套件的更多信息。 BTLE(蓝牙低能耗)开发套件-必须具有感应曲线
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.