Я новичок в рекламе Bluetooth с низким энергопотреблением. BLE поддерживает динамическую рекламу на уровне API 28. Поскольку вы можете рекламировать различные пакеты данных. Я пытаюсь сделать, но получаю код состояния 18 и Null в наборе рекламы.
Может кто-нибудь, пожалуйста, скажите мне, как я могу сделать динамическую рекламу в Android. Мое устройство - Nexus 6 с Android 8.1.0.
вот мой код:
//setting parameters
AdvertisingSetParameters parameters = (new AdvertisingSetParameters.Builder())
.setLegacyMode(false)
.setConnectable(true)
.setInterval(AdvertisingSetParameters.INTERVAL_HIGH)
.setTxPowerLevel(AdvertisingSetParameters.TX_POWER_MEDIUM)
.build();
//Adding advertising data
AdvertiseData.Builder mbuilder = new AdvertiseData.Builder();
mbuilder.setIncludeDeviceName(false);
mbuilder.setIncludeTxPowerLevel(false);
mbuilder.addManufacturerData(Integer.parseInt(manuf, 16), manufacturerData1);
AdvertiseData mData = mbuilder.build();
//Adding scan response data
AdvertiseData scanResponse = new AdvertiseData.Builder()
.setIncludeDeviceName(true)
.build();
//Advertising set call back and I am receiving null in Advertising set and status code 18
AdvertisingSetCallback callback = new AdvertisingSetCallback() {
@Override
public void onAdvertisingSetStarted(AdvertisingSet advertisingSet, int txPower, int status) {
Log.i("", "onAdvertisingSetStarted(): txPower:" + txPower + " , status: "
+ status);
if (status==AdvertisingSetCallback.ADVERTISE_FAILED_ALREADY_STARTED)
Toast.makeText(context, "ADVERTISE_FAILED_ALREADY_STARTED", Toast.LENGTH_SHORT).show();
else if (status==AdvertisingSetCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED)
Toast.makeText(context, "ADVERTISE_FAILED_FEATURE_UNSUPPORTED", Toast.LENGTH_SHORT).show();
else if (status==AdvertisingSetCallback.ADVERTISE_FAILED_DATA_TOO_LARGE)
Toast.makeText(context, "ADVERTISE_FAILED_DATA_TOO_LARGE", Toast.LENGTH_SHORT).show();
else if (status==AdvertisingSetCallback.ADVERTISE_FAILED_INTERNAL_ERROR)
Toast.makeText(context, "ADVERTISE_FAILED_INTERNAL_ERROR", Toast.LENGTH_SHORT).show();
else if (status==AdvertisingSetCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS)
Toast.makeText(context, "ADVERTISE_FAILED_TOO_MANY_ADVERTISERS", Toast.LENGTH_SHORT).show();
else if (status==AdvertisingSetCallback.ADVERTISE_SUCCESS)
Toast.makeText(context, "ADVERTISE_SUCCESS", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {
Log.i("", "onAdvertisingSetStopped():");
}
};
//starting advertisement
mBluetoothLeAdvertiser.startAdvertisingSet(parameters, mData, scanResponse, null, null, callback);