【发布时间】:2015-08-25 10:34:40
【问题描述】:
我正在尝试在连接状态更改为“正在连接、已连接、断开连接、断开连接”时接收通知。我注册了 ACTION_CONNECTION_STATE_CHANGED,但我总是在“switch-case”的“default”语句中收到日志。
请让我知道如何正确接收有关以下代码中 switch-case 中提到的状态的通知?
代码:
final int connState = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.ERROR);
switch (connState) {
case BluetoothAdapter.STATE_CONNECTED:
Log.d(TAG, LogAnd.show("onReceive", "BluetoothAdapter.STATE_CONNECTED"));
tvStatus.setText("BT STATE_CONNECTED.");
break;
case BluetoothAdapter.:
Log.d(TAG, LogAnd.show("onReceive", "BluetoothAdapter.STATE_CONNECTED"));
tvStatus.setText("BT STATE_CONNECTED.");
break;
case BluetoothAdapter.STATE_CONNECTING:
Log.d(TAG, LogAnd.show("onReceive", "BluetoothAdapter.STATE_CONNECTING"));
tvStatus.setText("BT is STATE_CONNECTING.");
break;
case BluetoothAdapter.STATE_DISCONNECTING:
Log.d(TAG, LogAnd.show("onReceive", "BluetoothAdapter.STATE_DISCONNECTING"));
tvStatus.setText("BT STATE_DISCONNECTING.");
break;
case BluetoothAdapter.STATE_DISCONNECTED:
Log.d(TAG, LogAnd.show("onReceive", "BluetoothAdapter.STATE_DISCONNECTED"));
tvStatus.setText("BT STATE_DISCONNECTED.");
break;
default:
Log.wtf(TAG, LogAnd.show("onReceive", "connState: UNHANDELED CASE."));
break;
}
break;
【问题讨论】:
标签: android android-intent broadcastreceiver intentfilter android-bluetooth