如何配对或编程方式删除已配对的蓝牙设备上的Andr​​oid? [英] How to unpair or delete paired bluetooth device programmatically on android?

查看:245
本文介绍了如何配对或编程方式删除已配对的蓝牙设备上的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该项目是用我的Andr​​oid手机与我的Arduino设备连接。但我怎么能解除配对配对的。我看到它似乎成对列表存储在那里bluetoothadapter可以随时检索。

The project is to use my android phone to connect with my arduino devices. but how can I unpair the paired ones. I see it seems the paired list is stored where bluetoothadapter could retrieve anytime.

PS: 第一次,我知道长preSS配对设备将取消配对它。
但这里的问题是,我怎么能做到这一点编程?

PS: 1st, I know long press paired device will unpair it.
but the question here is how can I make this happen programmatically?

2,我已经检查BluetoothDevice类和bluetoothAdapter类,没有函数来实现这一点。

2nd, I have checked bluetoothdevice and bluetoothAdapter class, there is no function to implement this.

感谢。

推荐答案

这code对我的作品。

This code works for me.

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());
}
}

这篇关于如何配对或编程方式删除已配对的蓝牙设备上的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆