Skip to content Skip to sidebar Skip to footer

Request Mtu Is Not Working In Nougat

I am working on App which is communicate with BLE device.I can write 20 bytes easily on characteristics but when it is more than 20 bytes it's create problem.I am using mBluetooth

Solution 1:

I was having this exact same issue, so I put the mtu request in a loop and it seems to work after 2 attempts regularly.

newThread(newRunnable() {
                @Overridepublicvoidrun() {
                    while (!mtuConfirmed) {
                        mBluetoothGatt.requestMtu(512);
                        mtuRequestCounter++;
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    Log.d(TAG, "MTU change reply received after " + mtuRequestCounter + " attempts");
                }
            }).start();

Solution 2:

I had the same problem. It was because I had multiple requests from the Gatt object at the same time. I called GATT.discoverServices() and GATT.requestMtu(512) at the same time. And always, only the first call worked. Gatt object has several callbacks, so for example, you can first request changing the MTU. Then when onMtuChanged is called, you call to ask for the other request. In my case, GATT.discoverServices()

Post a Comment for "Request Mtu Is Not Working In Nougat"