android 藍芽隱藏對話方塊 後臺配對
阿新 • • 發佈:2019-02-07
static public boolean createBond(Class btClass, BluetoothDevice btDevice)
throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Log.i("life", "createBondMethod = " + createBondMethod.getName());
Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
static public boolean setPin(Class btClass, BluetoothDevice btDevice,
String str) throws Exception {
Boolean returnValue = null;
try {
Method removeBondMethod = btClass.getDeclaredMethod("setPin",
new Class[] { byte[].class });
returnValue = (Boolean) removeBondMethod.invoke(btDevice,
new Object[] { str.getBytes() });
Log.i("life", "returnValue = " + returnValue);
} catch (SecurityException e) {
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
} catch (IllegalArgumentException e) {
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnValue;
}
// 取消使用者輸入
static public boolean cancelPairingUserInput(Class btClass,
BluetoothDevice device) throws Exception {
Method createBondMethod = btClass.getMethod("cancelPairingUserInput");
// cancelBondProcess()
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
Log.i("life", "cancelPairingUserInputreturnValue = " + returnValue);
return returnValue.booleanValue();
}