Я недавно получил Android 9.0 на моем устройстве Huawei Mate 9.
До этого у меня был Android 8, и BluetoothDevice.setPin до этого работал нормально.
Любые подсказки, почему это больше не работает?
public class BlututReceiver extends BroadcastReceiver {
private final static byte[] PIN = "0000".getBytes();
public void onReceive(android.content.Context r7, android.content.Intent intent) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String action = intent.getAction();
if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
sendPin(bluetoothDevice);
}
}
private void sendPin(BluetoothDevice bluetoothDevice) {
try {
Thread.sleep(100);
bluetoothDevice.setPin(PIN);
bluetoothDevice.createBond();
//bluetoothDevice.setPairingConfirmation(true);
//bluetoothDevice.getClass().getMethod("setPairingConfirmation", new Class[]{Boolean.TYPE}).invoke(bluetoothDevice, new Object[]{Boolean.valueOf(true)});
} catch (Exception e) {
Log.e("BLUETOOTHSETPINERR",e.getMessage());
}
}
}
<receiver android:name=".Utile.BlututReceiver">
<intent-filter android:priority="1000">
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
</receiver>