这段代码对我有用

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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐