在網上查了下,用該辦法清除已配對設備,華為手機上測驗沒有問題,但是小米手機不行。
private static void removePairDevice() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
mBluetoothAdapter.enable();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> bondedDevices = mBluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : bondedDevices) {
unpairDevice(device);
}
}
}
private static void unpairDevice(BluetoothDevice device) {
try {
Method m = device.getClass().getMethod("removeBond", (Class[]) null);
m.invoke(device, (Object[]) null);//清除失敗時,回傳false.
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
還有什么別的方法嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/189693.html
標籤:Android
上一篇:微信小程式提示Error: pages[0] 欄位需為 string麻煩看看哪里寫錯了
下一篇:呼叫webview的saveWebArchive()方法后 報錯如下:Failed to create file
