ACTION_ACL_DISCONNECTED
时间: 2023-09-30 08:07:21 浏览: 69
ACTION_ACL_DISCONNECTED是BluetoothDevice类中定义的一个广播动作,用于指示与远程设备的ACL(异步链路)连接断开。该广播始终包含额外字段EXTRA_DEVICE,用于指定与之断开连接的设备。ACL连接由Android Bluetooth堆栈自动管理。要接收此广播,需要具有BLUETOOTH权限。
相关问题
deviceAddress=EC:DA:***********action : android.bluetooth.device.action.ACL_DISCONNECTED
deviceAddress=EC:DA:***********是一个设备的蓝牙地址,action : android.bluetooth.device.action.ACL_DISCONNECTED是一个Android蓝牙设备的断开连接的动作。当一个蓝牙设备与Android设备的连接断开时,系统会发送这个动作给应用程序,以便应用程序可以做出相应的处理。
android 蓝牙 断开连接和取消配对的广播
在 Android 中,断开连接和取消配对的广播分别是 ACTION_ACL_DISCONNECTED 和 ACTION_BOND_STATE_CHANGED。
ACTION_ACL_DISCONNECTED 广播在 BluetoothAdapter 中定义,当蓝牙连接断开时发送。您可以使用以下代码注册和接收此广播:
```
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_ACL_DISCONNECTED.equals(action)) {
// 处理断开连接的逻辑
}
}
};
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_ACL_DISCONNECTED);
registerReceiver(mReceiver, filter);
```
ACTION_BOND_STATE_CHANGED 广播在 BluetoothDevice 中定义,当蓝牙设备配对状态更改时发送。您可以使用以下代码注册和接收此广播:
```
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
int previousBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
if (bondState == BluetoothDevice.BOND_NONE && previousBondState == BluetoothDevice.BOND_BONDED) {
// 处理取消配对的逻辑
}
}
}
};
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
registerReceiver(mReceiver, filter);
```