Android 断开已连接蓝牙的连接
通过配对连接蓝牙设备后发现有些设备包含两种属性媒体音频和通话音频;
通过反射调用断开连接的方法后判断连接状态还是已连接。
因为媒体音频是属于BluetoothProfile.A2DP
代理的
因为通话音频是属于BluetoothProfile.HEADSET
代理的
关闭时需要把他们全部关闭后获取的连接状态才是正确的。
断开对音频和通话的连接
- 方法调用
disconnect(BluetoothDevice);//要断开的蓝牙连接对象
* 需要连接/断开的蓝牙设备
*/
private BluetoothDevice currentBluetoothDevice;
private BluetoothAdapter mBluetoothAdapter; = BluetoothAdapter.getDefaultAdapter();
/**
* 断开蓝牙设备连接
*
* @param bluetoothDevice BluetoothDevice
*/
public void disconnect(BluetoothDevice bluetoothDevice) {
currentBluetoothDevice = bluetoothDevice;
//获取A2DP代理对象
mBluetoothAdapter.getProfile