I m building an Android application with Kotlin. With this application I can pairing bluetooth device. I need also to remove pairing by passing MacAddress of device. So I write the following code to remove pair with device:
pairedDevices = mBluetoothAdapter?.bondedDevices;
if (pairedDevices?.size!! > 0) {
for (device in pairedDevices!!) {
if(device.address.equals(d.macAddress)){
try {
val m: Method = device.javaClass
.getMethod("removeBond")
m.invoke(device, null as Array<Any?>?)
} catch (e: Exception) {
e.message?.let { Log.e("Removing has been failed.", it) }
}
}
}
}
The method is executed but after that if I try to go in bluetooth settings, the device that I removed with that method is still associated
edit
The error that I received is this:
Wrong number of arguments; expected 0, got 1