Android Things BLE Pairing无效

时间:2018-03-13 17:11:12

标签: android bluetooth-lowenergy android-things pairing

我正在尝试将我的pi3与Android内容配对到BLE设备。

的关注 https://developer.android.com/things/sdk/apis/bluetooth.html#device-pairing

我设置了一个pairingCallback:

mBluetoothConnectionManager = BluetoothConnectionManager.getInstance();
mBluetoothConnectionManager.registerPairingCallback(mBluetoothPairingCallback);

这是我的配对回调:

private BluetoothPairingCallback mBluetoothPairingCallback = new BluetoothPairingCallback() {

    @Override
    public void onPairingInitiated(BluetoothDevice bluetoothDevice,
                                   PairingParams pairingParams) {
        // Handle incoming pairing request or confirmation of outgoing pairing request
        Log.d(TAG,"onPairingInitiated");
        handlePairingRequest(bluetoothDevice, pairingParams);
    }

    @Override
    public void onPaired(BluetoothDevice bluetoothDevice) {
        // Device pairing complete
        Log.d(TAG,"onPaired");
    }

    @Override
    public void onUnpaired(BluetoothDevice bluetoothDevice) {
        // Device unpaired
        Log.d(TAG,"onUnpaired");
    }

    @Override
    public void onPairingError(BluetoothDevice bluetoothDevice,
                               PairingError pairingError) {
        // Something went wrong!
        Log.d(TAG,"onPairingError "+getPairingErrorVerbose(pairingError.getErrorCode()));
    }
};

并在handlePairingRequest中:

private void handlePairingRequest(final BluetoothDevice bluetoothDevice, PairingParams pairingParams) {
    switch (pairingParams.getPairingType()) {
        case PairingParams.PAIRING_VARIANT_DISPLAY_PIN:
        case PairingParams.PAIRING_VARIANT_DISPLAY_PASSKEY:
            // Display the required PIN to the user
            Log.d(TAG, "Display Passkey - " + pairingParams.getPairingPin());
            break;
        case PairingParams.PAIRING_VARIANT_PIN:
        case PairingParams.PAIRING_VARIANT_PIN_16_DIGITS:
            // Obtain PIN from the user
            //String pin = ...;
            // Pass the result to complete pairing
            //mBluetoothConnectionManager.finishPairing(bluetoothDevice, pin);
            break;
        case PairingParams.PAIRING_VARIANT_CONSENT:
        case PairingParams.PAIRING_VARIANT_PASSKEY_CONFIRMATION:
            // Complete the pairing process
            mBluetoothConnectionManager.finishPairing(bluetoothDevice);
            break;
    }
}

我收到PairingParams.PAIRING_VARIANT_CONSENT并继续使用finishPairing。

我的问题是,finishPairing将状态从BOND_BONDING更改为BOND_BONDED,但是我的设备配对缺少了某些内容并且设备没有连接,因为它在标准的android中(我有相同的Android移动应用程序,配对就可以了用户接受BluetoothPairingDialog中的配对。

似乎在BluetoothPairingDialog中执行mDevice.setPairingConfirmation(true); 其结果与mBluetoothConnectionManager.finishPairing(bluetoothDevice)不同;

在配对期间我错过了什么吗?

非常感谢。

0 个答案:

没有答案