added in API level 26

AdvertisingSet

public final class AdvertisingSet
extends Object

java.lang.Object
   ↳ android.bluetooth.le.AdvertisingSet


This class provides a way to control single Bluetooth LE advertising instance.

To get an instance of AdvertisingSet, call the BluetoothLeAdvertiser.startAdvertisingSet(AdvertisingSetParameters, AdvertiseData, AdvertiseData, PeriodicAdvertisingParameters, AdvertiseData, AdvertisingSetCallback) method.

Note: Most of the methods here require Manifest.permission.BLUETOOTH_ADMIN permission.

See also:

Summary

Public methods

void enableAdvertising(boolean enable, int duration, int maxExtendedAdvertisingEvents)

Enables Advertising.

void setAdvertisingData(AdvertiseData advertiseData)

Set/update data being Advertised.

void setAdvertisingParameters(AdvertisingSetParameters parameters)

Update advertising parameters associated with this AdvertisingSet.

void setPeriodicAdvertisingData(AdvertiseData periodicData)

Used to set periodic advertising data, must be called after setPeriodicAdvertisingParameters, or after advertising was started with periodic advertising data set.

void setPeriodicAdvertisingEnabled(boolean enable)

Used to enable/disable periodic advertising.

void setPeriodicAdvertisingParameters(PeriodicAdvertisingParameters parameters)

Update periodic advertising parameters associated with this set.

void setScanResponseData(AdvertiseData scanResponse)

Set/update scan response data.

Inherited methods

Public methods

enableAdvertising

added in API level 26
public void enableAdvertising (boolean enable, 
                int duration, 
                int maxExtendedAdvertisingEvents)

Enables Advertising. This method returns immediately, the operation status is delivered through callback.onAdvertisingEnabled().

Requires Manifest.permission.BLUETOOTH_ADMIN

Parameters
enable boolean: whether the advertising should be enabled (true), or disabled (false)

duration int: advertising duration, in 10ms unit. Valid range is from 1 (10ms) to 65535 (655,350 ms)

maxExtendedAdvertisingEvents int: maximum number of extended advertising events the controller shall attempt to send prior to terminating the extended advertising, even if the duration has not expired. Valid range is from 1 to 255.

setAdvertisingData

added in API level 26
public void setAdvertisingData (AdvertiseData advertiseData)

Set/update data being Advertised. Make sure that data doesn't exceed the size limit for specified AdvertisingSetParameters. This method returns immediately, the operation status is delivered through callback.onAdvertisingDataSet().

Advertising data must be empty if non-legacy scannable advertising is used.

Parameters
advertiseData AdvertiseData: Advertisement data to be broadcasted. Size must not exceed BluetoothAdapter.getLeMaximumAdvertisingDataLength(). If the advertisement is connectable, three bytes will be added for flags. If the update takes place when the advertising set is enabled, the data can be maximum 251 bytes long.

setAdvertisingParameters

added in API level 26
public void setAdvertisingParameters (AdvertisingSetParameters parameters)

Update advertising parameters associated with this AdvertisingSet. Must be called when advertising is not active. This method returns immediately, the operation status is delivered through callback.onAdvertisingParametersUpdated.

Parameters
parameters AdvertisingSetParameters: advertising set parameters.

setPeriodicAdvertisingData

added in API level 26
public void setPeriodicAdvertisingData (AdvertiseData periodicData)

Used to set periodic advertising data, must be called after setPeriodicAdvertisingParameters, or after advertising was started with periodic advertising data set. This method returns immediately, the operation status is delivered through callback.onPeriodicAdvertisingDataSet().

Parameters
periodicData AdvertiseData: Periodic advertising data. Size must not exceed BluetoothAdapter.getLeMaximumAdvertisingDataLength(). If the update takes place when the periodic advertising is enabled for this set, the data can be maximum 251 bytes long.

setPeriodicAdvertisingEnabled

added in API level 26
public void setPeriodicAdvertisingEnabled (boolean enable)

Used to enable/disable periodic advertising. This method returns immediately, the operation status is delivered through callback.onPeriodicAdvertisingEnable().

Parameters
enable boolean: whether the periodic advertising should be enabled (true), or disabled (false).

setPeriodicAdvertisingParameters

added in API level 26
public void setPeriodicAdvertisingParameters (PeriodicAdvertisingParameters parameters)

Update periodic advertising parameters associated with this set. Must be called when periodic advertising is not enabled. This method returns immediately, the operation status is delivered through callback.onPeriodicAdvertisingParametersUpdated().

Parameters
parameters PeriodicAdvertisingParameters

setScanResponseData

added in API level 26
public void setScanResponseData (AdvertiseData scanResponse)

Set/update scan response data. Make sure that data doesn't exceed the size limit for specified AdvertisingSetParameters. This method returns immediately, the operation status is delivered through callback.onScanResponseDataSet().

Parameters
scanResponse AdvertiseData: Scan response associated with the advertisement data. Size must not exceed BluetoothAdapter.getLeMaximumAdvertisingDataLength(). If the update takes place when the advertising set is enabled, the data can be maximum 251 bytes long.