【问题标题】:Android BLE BluetoothAdapter StatesAndroid BLE 蓝牙适配器状态
【发布时间】:2021-02-04 07:22:30
【问题描述】:

我正在使用 Android BluetoothAdapter 类来扫描并连接到 BLE 设备。在测试时,来自此类的一个日志记录了“STATE_BLE_ON”的蓝牙适配器状态。经过一些研究,可以将适配器置于某些模式中,以便用户可以关闭经典蓝牙但保持 LE 开启。但是,当我深入研究 BluetoothAdapter 类的代码时,无法访问此状态。唯一可以访问的状态是 STATE_ON、STATE_OFF、STATE_TURNING_ON、STATE_TURNING_OFF。那么测试设备是如何记录这个状态的呢?即使在 Android Developers 网站上,他们也没有提及 STATE_BLE_ON 状态。此状态在 BluetoothAdapter 类中,我只是看不到它被访问的任何地方,也不知道它如何在测试设备上记录此状态。 BluetoothAdapter.getState() 下面。


 * Get the current state of the local Bluetooth adapter.
 * <p>Possible return values are
 * {@link #STATE_OFF},
 * {@link #STATE_TURNING_ON},
 * {@link #STATE_ON},
 * {@link #STATE_TURNING_OFF}.
 *
 * @return current state of Bluetooth adapter
 

@RequiresPermission(Manifest.permission.BLUETOOTH)
@AdapterState
public int getState() {
    int state = getStateInternal();

    // Consider all internal states as OFF
    if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON
            || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
        if (VDBG) {
            Log.d(TAG, "Consider " + BluetoothAdapter.nameForState(state) + " state as OFF");
        }
        state = BluetoothAdapter.STATE_OFF;
    }
    if (VDBG) {
        Log.d(TAG, "" + hashCode() + ": getState(). Returning " + BluetoothAdapter.nameForState(
                state));
    }
    return state;
}***

【问题讨论】:

    标签: android bluetooth-lowenergy


    【解决方案1】:

    您绝对可以记录状态,因为它是 int。

    您无法访问STATE_BLE_ON 的原因是它被标记了@hide Javadoc 标记。

    见:What does @hide mean in the Android source code?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 2014-02-06
      相关资源
      最近更新 更多