我试图“抓”的时候,蓝牙从设备断开连接。 即时通讯正在使用此代码:
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)){
deleteNotification();
setWarningState(WarningState.RedWarning);
showNotification("You are parked");
但是,当IM断开通过关闭遥控设备或通过电话关闭蓝牙切换蓝牙也不会,如果statment进入这个。
使用该即时通讯时:
BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)
其还好吧工作(当aconnection是astablished)。 这是为什么,我怎么能使其工作? 谢谢!
您已经注册了下面IntenFilters
IntentFilter f1 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
IntentFilter f2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, f1);
this.registerReceiver(mReceiver, f2);
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(mBluetoothReceiver, filter);
private final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action!=null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_OFF:
break;
case BluetoothAdapter.STATE_ON:
break;
}
}
}
};