Requesting MTU with Bluetooth Low Energy connection on Android 4.3-4.4 (API 18-20)

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

I have a Bluetooth Low Energy Application which requires an MTU size above the default 23 bytes.

Though Android introduced BluetoothGatt#requestMTU() in API 21, is there any way, including use of private APIs, to accomplish this pre API 21?

回答1:

If you have control over the peripheral device, you can issue an MTU request (ATT_OP_MTU_REQ, opcode 0x02) from the peripheral. Android is capable of larger GATT MTUs (update: 517 bytes is the maximum value), if requested by the peripheral, and will happily send an according ATT_OP_MTU_RESP.

The only tricky thing is that the MTU exchange may not overlap with a fragmented read/write. One workaround might be a client-side sleep at a given time of the handshake, where the peripheral sends an MTU request. Another possible workaround would be a READ or WRITE on a "magic" characteristic that triggers the MTU exchange.

However, with an increased MTU, I'm much more often receiving Status=133 errors, possibly caused by a higher packet error rate with larger packets?



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