首页 > 技术文章 > Android Bluetooth 配对

ikaka 2014-03-20 09:58 原文

android 配对与取消配对的方法:

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

 

推荐阅读