Search code examples
androidkotlinbluetooth-lowenergyandroid-ble

Ble Android Advertising: AddServiceData


on my ble project i'm trying to add some service data to advertise data like this

 var data = AdvertiseData.Builder().apply {
            setIncludeDeviceName(true)
            addServiceData(
                ParcelUuid(BleConsts.SERVICE_UUID),
                myData.toByteArray(Charsets.UTF_8)
            )
        }

  bleAdvertiser.startAdvertising(
      settings.build(), 
      data.build(), 
      advertiseCallback
  )

but onStartFailure callback of my AdvertiseCallback implementation is triggered with error code 1. If i remove from data the addServiceData call, advertise start without any problem. What's wrong?


Solution

  • Error code 1 corresponds to the constant ADVERTISE_FAILED_DATA_TOO_LARGE. Your data must be 31 bytes or less:

    Failed to start advertising as the advertise data to be broadcasted is larger than 31 bytes.

    Try reducing the size of the data you are adding.