gpt4 book ai didi

Android BLE 广告失败,错误代码为 1

转载 作者:行者123 更新时间:2023-12-04 01:04:18 26 4
gpt4 key购买 nike

我有一个使用 BLE 来宣传一些数据的示例应用程序。但是,我的广告失败并显示错误代码 1。错误代码 1 基本上意味着有效负载大于广告数据包允许的 31 个字节。但从我的代码中,我可以看到有效负载小于 31 个字节。问题出在哪里?

一些建议关闭设备名称广告,因为长名称会占用空间。我也这样做了。

private void advertise(){
BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode( AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY )
.setTxPowerLevel( AdvertiseSettings.ADVERTISE_TX_POWER_HIGH )
.setTimeout(0)
.setConnectable( false )
.build();
ParcelUuid pUuid = new ParcelUuid( UUID.fromString( getString( R.string.ble_uuid ) ) );
//ParcelUuid pUuid = new ParcelUuid( UUID.randomUUID() );


AdvertiseData data = new AdvertiseData.Builder()
.setIncludeDeviceName(false)
.setIncludeTxPowerLevel(false)

.addServiceUuid( pUuid )
.addServiceData( pUuid, "D".getBytes() )
.build();
advertiser.startAdvertising( settings, data, advertisingCallback );
}

我希望这会宣传数据“D”,不会因错误代码 1 而失败。

最佳答案

在我看来,您将 pUuid 添加到广告数据中两次。一次单独使用,第二次使用数据“D”。 BLE 广告只有 1 个 UUID 的空间。尝试消除第一次调用:

.addServiceUuid(pUuid)

而是只使用:
.addServiceData(pUuid, "D".getBytes())

关于Android BLE 广告失败,错误代码为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57329113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com