Request MTU is not working in Nougat

纵饮孤独 提交于 2021-01-04 14:36:40

问题


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

mBluetoothGatt.requestMtu(512);

write charateristics after getting success.

 @Override
                    public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
                        super.onMtuChanged(gatt, mtu, status);

                        if (status == BluetoothGatt.GATT_SUCCESS) {
                            System.out.print("Mtu Granted");
//                            this.supportedMTU = mtu;
                        }
                    }

which is working fine in marshmallow and lolipop.But it is not working in Nougat(Samsung galaxy s6).


回答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.

            new Thread(new Runnable() {
                @Override
                public void run() {
                    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();


来源:https://stackoverflow.com/questions/46149114/request-mtu-is-not-working-in-nougat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!