要求MTU在牛轧糖中不起作用 [英] Request MTU is not working in Nougat

查看:137
本文介绍了要求MTU在牛轧糖中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与BLE设备通信的App上工作.我可以轻松地在特性上写20个字节,但是当它超过20个字节时就会造成问题.我正在使用

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);

获得成功后再写特征.

 @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;
                        }
                    }

它可以在棉花糖和棒棒糖中正常使用,但不能在牛轧糖(三星s6)中使用.

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

推荐答案

我遇到了完全相同的问题,因此我将mtu请求放入了一个循环,并且似乎在定期尝试2次后仍能正常工作.

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();

这篇关于要求MTU在牛轧糖中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆