android - 删除 Android 上所有配对的蓝牙设备

标签 android bluetooth bluetooth-lowenergy android-bluetooth

我想以编程方式删除 Android 手机上名称以“ABC”开头的配对蓝牙低功耗设备。

我正在使用 Android studio。

最佳答案

如果您对 BLE(低功耗蓝牙)有具体了解, 要获取所有绑定(bind)设备,您可以编写一个方法。

public List<BluetoothDevice> getConnectedDevices() {
        BluetoothManager btManager = (BluetoothManager)getSystemService(BLUETOOTH_SERVICE);
        return btManager.getConnectedDevices(BluetoothProfile.GATT);
    }

这将返回 GATT 配置文件中连接的 BLE 设备列表。 获取名称,确认这是否是您要断开连接的设备:

List<BluetoothDevice> btdevices = getConnectedDevices();
                for(int i=0;i<btdevices.size();i++)
                {
                    //match your device here
                    Log.d("saurav"," BLE Name:"+btdevices.get(i).getName());
            }

要断开连接,您只需调用disconnect方法即可。您需要与 gatt 实例断开连接(与用于连接 BLE 设备的 gatt 实例相同)。

public void disconnect() {
        if (gatt == null) {
            return;
        }
        gatt.disconnect();

    }

这将断开您的 BLE 设备。我个人有 teste tshi 并为我工作。

关于android - 删除 Android 上所有配对的蓝牙设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39531986/

相关文章:

android - onLongClick 用于 WebView 内的纯文本

Android 测试用例 - 如何查看输出?

java - 更改位于 Visual Studio 中不同位置的 SDK 的路径

javascript - 使用 react-native-ble-manager 获取可用蓝牙设备的列表

ios - 寻找触手可及的通用蓝牙设备

android - 开机小部件异常

ios - 如何检测蓝牙设备的音频来自哪个设备

android - 如何检测 BLE 设备何时不在范围内?

java - 如何避免调用 handler.postDelayed(Runnable run) ?

后台模式下的 iOS BLE 外设/广告数据