android 数值 最大长度,AndroidBLE中传输数据的最大长度怎么破
很简单嘛,改变传输的ATT的MTU就行了,大家经过友好的协商,得到双方都想要的结果,是最好的。在Android上(API21),改变ATTMTU的接口为: [java]viewplaincopy publicbooleanrequestMtu(intmtu)AddedinAPIlevel21 RequestanMTUsizeusedforagivenconnection。Whenperfor
很简单嘛,改变传输的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的长度的数据了。
全部
更多推荐
所有评论(0)