欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > Android >内容正文

Android

android requestmtu,android - 如何设置/获取/请求从Android到iOS或反之亦然BLE的MTU? - 堆栈内存溢出...

发布时间:2025/3/11 Android 59 豆豆
生活随笔 收集整理的这篇文章主要介绍了 android requestmtu,android - 如何设置/获取/请求从Android到iOS或反之亦然BLE的MTU? - 堆栈内存溢出... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我们正在将MTU请求从Android发送到iOS

Android-从此函数onServicesDiscovered回调请求MTU

但是我不知道如何确定对等设备支持是否请求了MTU,以及如何实际协商的MTU。 仅在API级别22(Android L 5.1)中添加了必需的函数:BluetoothGattCallback.onMtuChanged(BluetoothGatt gatt,int mtu,int状态)。

我的问题是我不知道我可以发送多少个字节的数据包。

@Override

public void onServicesDiscovered(BluetoothGatt gatt, int status) {

if (status == BluetoothGatt.GATT_SUCCESS) {

//requestPriorityHigh();

gatt.requestMtu(182);

broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);

List Services = gatt.getServices();

for (BluetoothGattService gattService : Services) {

if (SERVICE_UUID.equals(gattService.getUuid())) {

List gattCharacteristics = gattService.getCharacteristics();

for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {

if (CHARACTERISTIC_UUID.equals(gattCharacteristic.getUuid())) {

gatt.writeCharacteristic(gattCharacteristic);

List gattDescriptors = gattCharacteristic.getDescriptors();

for (BluetoothGattDescriptor gattDescriptor : gattDescriptors) {

gatt.readDescriptor(gattDescriptor);

}

}

}

}

}

} else {

Log.w(MainActivity.TAG, "onServicesDiscovered received: " + status);

}

}

例如:gatt.requestMtu(182)

iOS-未触发didSubscribeTo特征回调

- (void)peripheralManager:(CBPeripheralManager )peripheral central:(CBCentral )central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic

{

NOTIFY_MTU = central.maximumUpdateValueLength;

NSLog(@"Central subscribed to characteristic");

NSLog(@"Supported to BLE Device Info:--> %lu",(unsigned long)[central maximumUpdateValueLength]);

[peripheral setDesiredConnectionLatency:CBPeripheralManagerConnectionLatencyLow forCentral:central];

}

我们需要根据连接的BLE Devices.U设置数据包大小,如果未请求MTU,则对didSubscribeTo特性进行回调,最小MTU大小为20。如何从android获取和设置此mtu大小。

我们如何设置MTU?

总结

以上是生活随笔为你收集整理的android requestmtu,android - 如何设置/获取/请求从Android到iOS或反之亦然BLE的MTU? - 堆栈内存溢出...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。