Search code examples
androidandroid-intentbluetoothbroadcastreceiverintentfilter

Integer returned by intent has no correponding constant value


I registered the bluetooth for ACTION_BOND_STATE_CHANGED, and when i run the App, non of the cases in the switch-case statement executes, and what i receive is an integer value as shown below and i do not know the meaning of it.

how can i interpret it?

Code:

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

Solution

  • The value you are getting is the constant ERROR error. You should handle this case too.
    Since there are few more optional returned values, like DEVICE_TYPE_CLASSIC, DEVICE_TYPE_DUAL and so on, I suggest you handle them also. If you have no interest in them, you can add a DEFAULT statement.