Intent返回的整数没有对应的常量值

Integer returned by intent has no correponding constant value

我为 ACTION_BOND_STATE_CHANGED 注册了蓝牙,当我 运行 应用程序时,switch-case 语句中的所有情况都没有执行,我收到了什么 是一个整数值,如下所示,我不知道它的含义。

我该如何解读?

代码:

int currBondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
            Log.d(TAG, LogAnd.show("onReceive", "currBondState: "+currBondState));
            switch (currBondState) {
            case BluetoothDevice.BOND_BONDING:
                Log.d(TAG, LogAnd.show("onReceive", "currBondState: BOND_BONDING"));
                tvStatus.setText("currBondState:BOND_BONDING");
                break;
            case BluetoothDevice.BOND_BONDED:
                Log.d(TAG, LogAnd.show("onReceive", "currBondState: BOND_BONDED"));
                tvStatus.setText("currBondState:BOND_BONDED");
                break;
            case BluetoothDevice.BOND_NONE:
                Log.d(TAG, LogAnd.show("onReceive", "currBondState: BOND_NONE"));
                tvStatus.setText("currBondState:BOND_NONE");
                break;
            }

08-25 17:16:06.803: D/MainActivity(22326): -> onReceive:currBondState: -2147483648
08-25 17:16:06.803: D/MainActivity(22326): -> onReceive:prevBondState: -2147483648

您得到的值是常量 ERROR error。你也应该处理这个案子。
由于可选的返回值比较少,比如DEVICE_TYPE_CLASSICDEVICE_TYPE_DUAL等,建议你也处理一下。如果您对它们不感兴趣,可以添加一个DEFAULT声明。

intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);

此行将 return 来自意图的 BluetoothDevice.EXTRA_BOND_STATE 值或 BluetoothDevice.ERROR 如果该值不存在

在您的情况下,returned 的值是 BluetoothDevice.ERROR,在您的 switch 语句中没有 case