很简单嘛,改变传输的ATT的MTU就行了,大家经过友好的协商,得到双方都想要的结果,是最好的。在Android上(API21),改变ATTMTU的接口为:  [java]viewplaincopy  publicbooleanrequestMtu(intmtu)AddedinAPIlevel21  RequestanMTUsizeusedforagivenconnection。

Whenperformingawriterequestoperation(writewithoutresponse),thedatasentistruncatedtotheMTUsize。ThisfunctionmaybeusedtorequestalargerMTUsizetobeabletosendmoredataatonce。

AonMtuChanged(BluetoothGatt,int,int)callbackwillindicatewhetherthisoperationwassuccessful。RequiresBLUETOOTHpermission。Returns  true,ifthenewMTUvaluehasbeenrequestedsuccessfully  大声的说出来你想要一下子传多少,调用上面的接口就可以了,然后在下面的函数中看最终结果(当然了,如果你的peripheral申请改变MTU并且成功的话,那这个回调也会被调用):  [java]viewplaincopy  @Override  publicvoidonMtuChanged(BluetoothGattgatt,intmtu,intstatus){  super。

onMtuChanged(gatt,mtu,status);if(status==BluetoothGatt。GATT_SUCCESS){  this。supportedMTU=mtu;//localvartorecordMTUsize  }  }  之后你就可以快乐的发送supportedMTU-3的长度的数据了。

全部

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐