如何使用意图中的附加功能

How to use extras from the intent

我正在学习如何通过 android 使用蓝牙,并且我为 BluetoothAdapter.ACTION_STATE_CHANGED 注册了一个 BroadCastReceiver。 在文档中,它说

Broadcast Action: The state of the local Bluetooth adapter has been changed. For example, Bluetooth has been turned on or off. Always contains the extra fields EXTRA_STATE and EXTRA_PREVIOUS_STATE
containing the new and old states respectively.

现在,我该如何使用 EXTRA_STATE 和 EXTRA_PREVIOUS_STATE?

来自here

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                             BluetoothAdapter.ERROR);
        switch (state) {
        case BluetoothAdapter.STATE_OFF:
            //Bluetooth off
            break;
        case BluetoothAdapter.STATE_TURNING_OFF:
            //Turning Bluetooth off...
            break;
        case BluetoothAdapter.STATE_ON:
            //Bluetooth on
            break;
        case BluetoothAdapter.STATE_TURNING_ON:
            //Turning Bluetooth on...
            break;
        }
    }
}

};