BluetoothGatt: onClientRegistered () - status = 133 // onConnectionStateChange status: 257 - PullRequest
0 голосов
/ 26 июня 2019

После обновления платформ Cordova и Android и iOS приложение больше не подключается, и я не могу понять, почему?Logcat в Android Studio постоянно повторяет ту же ошибку, что и BluetoothGatt.Я noobish, поэтому я не совсем уверен, как отлаживать отсюда, кроме поиска в Google и задавать вопросы.

Я попытался удалить, обновить Gradle, изменил плагины для Wi-Fi, но я считаю, что это ошибка Bluetooth.Но мои убеждения, вероятно, ошибочны.

Цикл в Logcat в Android-студии.

D/BluetoothAdapter: STATE_ON
    scan not started yet
I/@@@@@@: @@@ connect
I/@@@@@@: @@@ creating gatt handler
    @@@ getRemoteDevice
    @@@ connectGatt
D/BluetoothAdapter: STATE_ON
D/BluetoothGatt: connect() - device: B8:27:EB:C6:4F:19, auto: false
D/BluetoothAdapter: isSecureModeEnabled
D/BluetoothGatt: registerApp()
    registerApp() - UUID=ae27921d-3fa8-45f4-bf37-b1d9abf04149
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/@@@@@@: @@@ onConnectionStateChange status: 257 newState: 0
    @@@ connect error - status: 257
D/BluetoothAdapter: stopLeScan()
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: scan not started yet
I/@@@@@@: @@@ connect
I/@@@@@@: @@@ creating gatt handler
    @@@ getRemoteDevice
    @@@ connectGatt
D/BluetoothAdapter: STATE_ON
D/BluetoothGatt: connect() - device: B8:27:EB:C6:4F:19, auto: false
D/BluetoothAdapter: isSecureModeEnabled
D/BluetoothGatt: registerApp()
    registerApp() - UUID=33e7344c-33e8-4366-8bd9-9336b80f4ce7
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/@@@@@@: @@@ onConnectionStateChange status: 257 newState: 0
    @@@ connect error - status: 257
D/BluetoothAdapter: stopLeScan()
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: scan not started yet

Это функция, которая выдает ошибки.

    // Also maintains the per-device operation queue.
    private class GattHandler extends BluetoothGattCallback
    {
        // Local copy of the key to BLE.mGatt. Fed by BLE.mNextGattHandle.
        final int mHandle;

        // The queue of operations.
        LinkedList<Runnable> mOperations = new LinkedList<Runnable>();

        // connect() and rssi() are handled separately from other operations.
        CallbackContext mConnectContext;
        CallbackContext mRssiContext;
        CallbackContext mCurrentOpContext;

        // Flag used when writing notification config descriptor.
        // In this case we don't want to send back the result to JavaScript.
        boolean mDontReportWriteDescriptor = false;

        // The Android API connection.
        BluetoothGatt mGatt;

        // Maps of integer to Gatt subobject.
        HashMap<Integer, BluetoothGattService> mServices;
        HashMap<Integer, BluetoothGattCharacteristic> mCharacteristics;
        HashMap<Integer, BluetoothGattDescriptor> mDescriptors;

        // Monotonically incrementing key to the subobject maps.
        int mNextHandle = 1;

        // Notification callbacks. The BluetoothGattCharacteristic object, as found
        // in the mCharacteristics map, is the key.
        HashMap<BluetoothGattCharacteristic, CallbackContext> mNotifications =
            new HashMap<BluetoothGattCharacteristic, CallbackContext>();

        GattHandler(int h, CallbackContext cc)
        {
            mHandle = h;
            mConnectContext = cc;
        }

        // Run the next operation, if any.
        // TODO: Make another method processNext that sets mCurrentOpContext to
        // null and calls process. That would clean up repeated code a bit.
        // Also consider writing method that adds a runnable to the mOperations
        // queue and calls process, this would also reduce some repeated code.
        void process()
        {
            if (mCurrentOpContext != null) return;
            Runnable runnable = mOperations.poll();
            if (runnable == null) return;
            runAction(runnable);
        }

        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
        {
            Log.i("@@@@@@", "@@@ onConnectionStateChange status: " + status + " newState: " + newState);

            if (status == BluetoothGatt.GATT_SUCCESS)
            {
                try
                {
                    JSONObject result = new JSONObject();
                    result.put("deviceHandle", mHandle);
                    result.put("state", newState);
                    Log.i("@@@@@@", "@@@ connect success");
                    keepCallback(mConnectContext, result);
                }
                catch(JSONException e)
                {
                    Log.i("@@@@@@", "@@@ connect error: " + e);
                    e.printStackTrace();
                    mConnectContext.error("Connect error: " + e);
                    //assert(false);
                }
            }
            else
            {
                // Could this be where we get 133? Yes it is.
                Log.i("@@@@@@", "@@@ connect error - status: " + status);
                mConnectContext.error(status);
            }
        }

Мне просто хотелось бы получить несколько крошек или указание о том, как решить эту проблему или как правильно выполнить отладку через Android-студию.Спасибо

1 Ответ

0 голосов
/ 28 июня 2019

Эта ошибка возникала из-за того, что я неправильно подключался к Wi-Fi, и код, который у меня был до обновления Cordova, и платформы iOS и Android работали нормально. Мне нужно было изменить android: используетCleartextTraffic = true в AndroidManifest в соответствии с документами Cordova при обновлении уровня API. Который имеет хороший ответ здесь .. Android 8: HTTP-трафик в открытом тексте запрещен

и документы: https://developer.android.com/training/articles/security-config

Надеюсь, это поможет тому, кто обновляет свой проект.

...