2012-09-27 28 views
0

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

任何帮助深表感谢。

回答

1

什么是您正在使用的蓝牙低功耗开发套件?

截至目前,Android没有蓝牙低功耗设备的本地API。 您可能不得不使用第三方API,例如Br​​oadcomm或TI或CSR的BLE。

http://code.google.com/p/broadcom-ble/

摩托罗拉蓝牙低能量的API http://developer.motorola.com/docs/bluetooth-low-energy-api/

你可以看一下这个网页,选择开发工具包的更多信息。 BTLE (Bluetooth Low energy) development kit - must have proximity profile

+0

我已经有几个配置文件与供应商提供的jar实现。而且我知道何时连接配置文件,断开连接等。但是,尽管Android系统调用上述方法,但我没有办法找到BLE设备的连接状态,与传统设备的连接状态不同该方法。 – user1400538

+0

您能否详细说明您的要求?为什么你需要使用这个功能?你可以尝试第三方API – m4n07