如何在Android中断开绑定的蓝牙设备

nhaq1z21  于 2023-04-10  发布在  Android
关注(0)|答案(1)|浏览(572)

我可以使用下面的代码解除绑定,但我如何简单地执行断开连接?

val pair = device.javaClass.getMethod("removeBond")
pair.isAccessible = true
pair.invoke(device)
u1ehiz5o

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。

相关问题