简体   繁体   English

Android BLE 蓝牙适配器状态

[英]Android BLE BluetoothAdapter States

I am working with Android BluetoothAdapter class to scan and connect to BLE devices.我正在使用 Android BluetoothAdapter class 扫描并连接到 BLE 设备。 While testing, one log that came up from this class logged a BluetoothAdapter State of "STATE_BLE_ON".测试时,来自此 class 的一个日志记录了“STATE_BLE_ON”的蓝牙适配器 State。 After some research, there are modes that the Adapter can be placed in so the user can turn off the classic bluetooth but leave LE on.经过一些研究,可以将适配器放置在某些模式中,以便用户可以关闭经典蓝牙但保持 LE 开启。 However, when I dug into the code of the BluetoothAdapter class, there is no way to access this state.但是,当我深入研究蓝牙适配器 class 的代码时,无法访问此 state。 The only states that can be accessed are STATE_ON, STATE_OFF, STATE_TURNING_ON, STATE_TURNING_OFF.唯一可以访问的状态是 STATE_ON、STATE_OFF、STATE_TURNING_ON、STATE_TURNING_OFF。 So how is the testing device Logging this state?那么测试设备是如何记录这个 state 的呢? Even on Android Developers website they do not mention the STATE_BLE_ON state.即使在 Android 开发人员网站上,他们也没有提到 STATE_BLE_ON state。 This state is in the BluetoothAdapter class, I just do not see anywhere it is accessed, nor do I know how it could Log this state on a testing device.这个 state 在蓝牙适配器 class 中,我只是看不到它被访问的任何地方,也不知道它如何在测试设备上记录这个 state。 BluetoothAdapter.getState() below. 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;
}***

You can absolutely log the state, as it is an int .您绝对可以记录 state,因为它是一个int

The reason you can't access STATE_BLE_ON , is because it is marked with the @hide Javadoc tag.您无法访问STATE_BLE_ON的原因是因为它标有@hide Javadoc 标记。

See: What does @hide mean in the Android source code?请参阅: Android 源代码中的@hide 是什么意思?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM