Android BLE 蓝牙适配器状态

问题描述 投票:0回答:1

我正在使用 Android BluetoothAdapter 类来扫描并连接到 BLE 设备。在测试时,此类产生的一个日志记录了“STATE_BLE_ON”的蓝牙适配器状态。经过一番研究后,适配器可以处于多种模式,以便用户可以关闭经典蓝牙但保持 LE 开启。但是,当我深入研究 BluetoothAdapter 类的代码时,无法访问此状态。唯一可以访问的状态是 STATE_ON、STATE_OFF、STATE_TURNING_ON、STATE_TURNING_OFF。那么测试设备是如何记录这个状态的呢?即使在 Android 开发者网站上,他们也没有提及 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个回答
0
投票

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

int

您无法访问

STATE_BLE_ON
的原因是因为它标有
@hide
Javadoc 标签。

参见:Android源代码中@hide是什么意思?

© www.soinside.com 2019 - 2024. All rights reserved.