这段代码对我有用

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

}

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐