我试图在没有用户交互的情况下配对蓝牙(BLE)设备 - 意味着配对将仅以编程方式完成,用户不会选择蓝牙设备而不会输入密码 . 我正在使用以下代码:
//request receiver
IntentFilter pairingRequestFilter = new
IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
this.registerReceiver(mPairingRequestRecevier, pairingRequestFilter);
BluetoothManager bluetoothManager = (BluetoothManager)
this.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
BluetoothDevice mDevice = bluetoothAdapter.getRemoteDevice("macaddress");
mDevice.setPairingConfirmation(true);
mDevice.setPin("1234".getBytes());
mDevice.createBond();
private final BroadcastReceiver mPairingRequestRecevier = new
BroadcastReceiver()
{
@Ove