I m building an Android application usign Kotlin, with this application I manage bluetooth device. Now I need to umpaired Bluetooth device programmatically. So I build the following code:
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", null)
m.invoke(device, null as Array<Any?>?)
} catch (e: Exception) {
e.message?.let { Log.e("Removing has been failed.", it) }
}
}
}
}
But if I try to execute this code:
val m: Method = device.javaClass
.getMethod("removeBond", null)
I received the following error:
java.lang.NoSuchMethodException: parameter type is null
How can I fixed it?