Added in API level 26

AdvertisingSet


class AdvertisingSet
kotlin.Any
   ↳ android.bluetooth.le.AdvertisingSet

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

To get an instance of AdvertisingSet, call the android.bluetooth.le.BluetoothLeAdvertiser#startAdvertisingSet method.

Summary

Public methods
Unit
enableAdvertising(enable: Boolean, duration: Int, maxExtendedAdvertisingEvents: Int)

Enables Advertising.

Unit

Set/update data being Advertised.

Unit

Update advertising parameters associated with this AdvertisingSet.

Unit

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

Unit

Used to enable/disable periodic advertising.

Unit

Update periodic advertising parameters associated with this set.

Unit

Set/update scan response data.

Public methods

enableAdvertising

Added in API level 26
fun enableAdvertising(
    enable: Boolean,
    duration: Int,
    maxExtendedAdvertisingEvents: Int
): Unit

Enables Advertising. This method returns immediately, the operation status is delivered through callback.onAdvertisingEnabled().
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

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
fun setAdvertisingData(advertiseData: AdvertiseData!): Unit

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.
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

Parameters
advertiseData AdvertiseData!: Advertisement data to be broadcasted. Size must not exceed android.bluetooth.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
fun setAdvertisingParameters(parameters: AdvertisingSetParameters!): Unit

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.
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

Parameters
parameters AdvertisingSetParameters!: advertising set parameters.

setPeriodicAdvertisingData

Added in API level 26
fun setPeriodicAdvertisingData(periodicData: AdvertiseData!): Unit

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().
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

Parameters
periodicData AdvertiseData!: Periodic advertising data. Size must not exceed android.bluetooth.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
fun setPeriodicAdvertisingEnabled(enable: Boolean): Unit

Used to enable/disable periodic advertising. This method returns immediately, the operation status is delivered through callback.onPeriodicAdvertisingEnable().
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

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

setPeriodicAdvertisingParameters

Added in API level 26
fun setPeriodicAdvertisingParameters(parameters: PeriodicAdvertisingParameters!): Unit

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().
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

setScanResponseData

Added in API level 26
fun setScanResponseData(scanResponse: AdvertiseData!): Unit

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().
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

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.