android蓝牙自动配对的问题
android蓝牙自动配对遇到是SSP配对时,那种只弹出“蓝牙配对申请”框,只需要点击“配对”和“不配对”,这时候我的广播监听函数如下
public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
try {
BtConnectOperation.BtSetPairingConfirmation(device.getClass(), device);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mConnService.pairEnd();
}
}
}
//设置确定
static public boolean BtSetPairingConfirmation(Class btClass, BluetoothDevice device)
throws Exception {
Method SetPairingConfirmationMethod = btClass.getMethod("setPairingConfirmation",
boolean.class);
Boolean returnValue = false;
returnValue = (Boolean)SetPairingConfirmationMethod.invoke(device, true);
return returnValue;
}