![](/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.