for a specific setup I need a way to automatically forget a bluetooth device my phone was connected to. I can use the name or the mac-address, that doesn't matter to me. but I need to be able to disable it without the need to manually interact with the settings app.
AFAIK there's no public method to do so, if you do not want to do it manually, you can do it using reflection using the removeBond
method, it is a bit ugly, but it worked for me in old project.
fun removeBond(device: BluetoothDevice) {
try {
device::class.java.getMethod("removeBond").invoke(device)
} catch (e: Exception) {
//RemovingBond failed
}
}
ADB command should be something like this
adb shell pm grant your.package.name android.permission.BLUETOOTH_ADMIN
adb shell am start -a android.bluetooth.device.action.REMOVE_BONDED --es android.bluetooth.device.extra.DEVICE "MAC:ADDRESS"