android - 如何在 android 上以编程方式取消配对或删除配对的蓝牙设备?

标签 android bluetooth arduino

该项目是使用我的安卓手机连接我的 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/

相关文章:

android - Google 语音识别器无法在 Android 4.x 上启动

安卓多点触控支持

android - 更改蓝牙可发现性时未发送广播

android - Android 媒体 Controller 与传输控件的区别

android - 如何在奥利奥中以编程方式获取移动蓝牙MAC地址

Java/Android - 使用 4 字节 MIC 解密 AES/CCM

arduino - 将输出引脚连接到输入引脚

arduino - 什么是常数 ARDUINO?以前是 22,现在是 100

c++ - 如何使用 avr-gcc 在 C/C++ 中执行预主初始化?

java - 在 Android 中使用 RecyclerView 不显示列表