klaudyuxxx
klaudyuxxx

Reputation: 374

Bluetooth setPin Android 9 Pie not working anymore

I recently got Android 9.0 on my Huawei Mate 9 device. Before I had Android 8, and BluetoothDevice.setPin was working fine until then. Any clues why this isn't working anymore?

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>

Upvotes: 0

Views: 706

Answers (1)

Raul
Raul

Reputation: 1

It works fine in a Xiaomi Mi 9 with Android Pie. It seems to be a problem of Huawei. I tried with HUAWEI P10 and HUAWEI PSMART (both with Android Pie) and it's not working.

Upvotes: 0

Related Questions