Я занимаюсь разработкой приложения для Android с функцией автоматического сопряжения по Bluetooth, поэтому диалоговое окно не появляется, код в виде удара:
Я искал веб-сайт, например, Bluetooth-соединение Android без ввода PIN-кода и подтверждения пользователяИспользование Android API
device.createBond();
private BroadcastReceiver Receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if(action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)){
try {
int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) {
int keycode = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, 0);
byte[] pinBytes = (""+keycode).getBytes("UTF-8");
device.setPin(pinBytes);
////device.setPairingConfirmation(true); ////Manifest.permission.BLUETOOTH_PRIVILEGED is needed, so we cannot use it directly or by java reflection ?
abortBroadcast(); //// prevent the pop dialog
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
, поскольку setPairingConfirmation не может быть использовано из-за BLUETOOTH_PRIVILEGED, какой-нибудь обходной метод?спасибо