2

以下是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);

getConnectionSummary()无论是 Classic 还是 Bluetooth Low energy 设备尝试连接,android 系统都会调用该方法;但与经典设备不同的是,由于我们没有获取蓝牙低功耗设备的连接状态的方法,因此我们无法正确更新低功耗设备的连接状态。

这个类的完整源代码可以在这里找到

任何帮助深表感谢。

4

1 回答 1

0

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

截至目前,Android 没有用于蓝牙低功耗设备的原生 API。您可能必须使用第三方 API,例如 Broadcomm 或 TI 或 CSR 的 BLE。

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

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

您可以查看此页面以获取有关选择开发套件的更多信息。 BTLE(低功耗蓝牙)开发套件 - 必须具有接近配置文件

于 2012-09-27T08:40:21.630 回答