该项目是使用我的安卓手机连接我的 arduino 设备。但我怎样才能取消配对的配对。我看到配对列表似乎存储在蓝牙适配器可以随时检索的位置。
PS:
1、我知道长按配对设备会取消配对。
但这里的问题是如何以编程方式实现这一点?
第二,我检查了bluetoothdevice和bluetoothAdapter类,没有实现这个的函数。
谢谢。
最佳答案
此代码对我有用。
private void pairDevice(BluetoothDevice device) {
try {
if (D)
Log.d(TAG, "Start Pairing...");
waitingForBonding = true;
Method m = device.getClass()
.getMethod("createBond", (Class[]) null);
m.invoke(device, (Object[]) null);
if (D)
Log.d(TAG, "Pairing finished.");
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
private void unpairDevice(BluetoothDevice device) {
try {
Method m = device.getClass()
.getMethod("removeBond", (Class[]) null);
m.invoke(device, (Object[]) null);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
关于android - 如何在 android 上以编程方式取消配对或删除配对的蓝牙设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9608140/