我为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
答案 0 :(得分:1)
您获得的值是常量ERROR
error。你也应该处理这个案子
由于还有更多可选的返回值,例如DEVICE_TYPE_CLASSIC
,DEVICE_TYPE_DUAL
等,我建议您也处理它们。如果您对它们不感兴趣,可以添加DEFAULT
声明。
答案 1 :(得分:0)
intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
此行将返回意图中的BluetoothDevice.EXTRA_BOND_STATE
值,如果值不存在,则返回BluetoothDevice.ERROR
。
在您的情况下,返回的值为BluetoothDevice.ERROR
,case
语句中没有switch
。