我可以使用下面的代码解除绑定,但我如何简单地执行断开连接?
val pair = device.javaClass.getMethod("removeBond") pair.isAccessible = true pair.invoke(device)
u1ehiz5o1#
试试这个瓦尔bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()瓦尔bluetoothDevice = bluetoothAdapter.getRemoteDevice(“MAC_ADDRESS_OF_DEVICE”)瓦尔bluetoothSocket = bluetoothDevice?.createRfcommSocketToServiceRecord(MY_UUID)bluetoothSocket()将“MAC_ADDRESS_OF_DEVICE”替换为要断开连接的蓝牙设备的MAC地址,将MY_UUID替换为设备连接到的蓝牙服务的UUID。
1条答案
按热度按时间u1ehiz5o1#
试试这个
瓦尔bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
瓦尔bluetoothDevice = bluetoothAdapter.getRemoteDevice(“MAC_ADDRESS_OF_DEVICE”)
瓦尔bluetoothSocket = bluetoothDevice?.createRfcommSocketToServiceRecord(MY_UUID)
bluetoothSocket()
将“MAC_ADDRESS_OF_DEVICE”替换为要断开连接的蓝牙设备的MAC地址,将MY_UUID替换为设备连接到的蓝牙服务的UUID。