我想以编程方式删除 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/