Skip to content

Most visited

Recently visited

navigation

BluetoothLeAdvertiser

public final class BluetoothLeAdvertiser
extends Object

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


This class provides a way to perform Bluetooth LE advertise operations, such as starting and stopping advertising. An advertiser can broadcast up to 31 bytes of advertisement data represented by AdvertiseData.

To get an instance of BluetoothLeAdvertiser, call the getBluetoothLeAdvertiser() method.

Note: Most of the methods here require BLUETOOTH_ADMIN permission.

See also:

Summary

Public methods

void startAdvertising(AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseCallback callback)

Start Bluetooth LE Advertising.

void startAdvertising(AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseData scanResponse, AdvertiseCallback callback)

Start Bluetooth LE Advertising.

void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData, AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData, int duration, int maxExtendedAdvertisingEvents, AdvertisingSetCallback callback)

Creates a new advertising set.

void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData, AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData, int duration, int maxExtendedAdvertisingEvents, AdvertisingSetCallback callback, Handler handler)

Creates a new advertising set.

void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData, AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData, AdvertisingSetCallback callback)

Creates a new advertising set.

void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData, AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData, AdvertisingSetCallback callback, Handler handler)

Creates a new advertising set.

void stopAdvertising(AdvertiseCallback callback)

Stop Bluetooth LE advertising.

void stopAdvertisingSet(AdvertisingSetCallback callback)

Used to dispose of a AdvertisingSet object, obtained with startAdvertisingSet(AdvertisingSetParameters, AdvertiseData, AdvertiseData, PeriodicAdvertisingParameters, AdvertiseData, AdvertisingSetCallback).

Inherited methods

From class java.lang.Object

Public methods

startAdvertising

added in API level 21
void startAdvertising (AdvertiseSettings settings, 
                AdvertiseData advertiseData, 
                AdvertiseCallback callback)

Start Bluetooth LE Advertising. On success, the advertiseData will be broadcasted. Returns immediately, the operation status is delivered through callback.

Requires BLUETOOTH_ADMIN permission.

Parameters
settings AdvertiseSettings: Settings for Bluetooth LE advertising.

advertiseData AdvertiseData: Advertisement data to be broadcasted.

callback AdvertiseCallback: Callback for advertising status.

startAdvertising

added in API level 21
void startAdvertising (AdvertiseSettings settings, 
                AdvertiseData advertiseData, 
                AdvertiseData scanResponse, 
                AdvertiseCallback callback)

Start Bluetooth LE Advertising. The advertiseData will be broadcasted if the operation succeeds. The scanResponse is returned when a scanning device sends an active scan request. This method returns immediately, the operation status is delivered through callback.

Requires BLUETOOTH_ADMIN

Parameters
settings AdvertiseSettings: Settings for Bluetooth LE advertising.

advertiseData AdvertiseData: Advertisement data to be advertised in advertisement packet.

scanResponse AdvertiseData: Scan response associated with the advertisement data.

callback AdvertiseCallback: Callback for advertising status.

startAdvertisingSet

added in API level 26
void startAdvertisingSet (AdvertisingSetParameters parameters, 
                AdvertiseData advertiseData, 
                AdvertiseData scanResponse, 
                PeriodicAdvertisingParameters periodicParameters, 
                AdvertiseData periodicData, 
                int duration, 
                int maxExtendedAdvertisingEvents, 
                AdvertisingSetCallback callback)

Creates a new advertising set. If operation succeed, device will start advertising. This method returns immediately, the operation status is delivered through callback.onAdvertisingSetStarted().

Parameters
parameters AdvertisingSetParameters: advertising set parameters.

advertiseData AdvertiseData: Advertisement data to be broadcasted. Size must not exceed getLeMaximumAdvertisingDataLength(). If the advertisement is connectable, three bytes will be added for flags.

scanResponse AdvertiseData: Scan response associated with the advertisement data. Size must not exceed getLeMaximumAdvertisingDataLength().

periodicParameters PeriodicAdvertisingParameters: periodic advertisng parameters. If null, periodic advertising will not be started.

periodicData AdvertiseData: Periodic advertising data. Size must not exceed getLeMaximumAdvertisingDataLength().

duration int: advertising duration, in 10ms unit. Valid range is from 1 (10ms) to 65535 (655,350 ms). 0 means advertising should continue until stopped.

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. 0 means no maximum.

callback AdvertisingSetCallback: Callback for advertising set.

Throws
IllegalArgumentException when any of the data parameter exceed the maximum allowable size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising feature is made when it's not supported by the controller.

startAdvertisingSet

added in API level 26
void startAdvertisingSet (AdvertisingSetParameters parameters, 
                AdvertiseData advertiseData, 
                AdvertiseData scanResponse, 
                PeriodicAdvertisingParameters periodicParameters, 
                AdvertiseData periodicData, 
                int duration, 
                int maxExtendedAdvertisingEvents, 
                AdvertisingSetCallback callback, 
                Handler handler)

Creates a new advertising set. If operation succeed, device will start advertising. This method returns immediately, the operation status is delivered through callback.onAdvertisingSetStarted().

Parameters
parameters AdvertisingSetParameters: Advertising set parameters.

advertiseData AdvertiseData: Advertisement data to be broadcasted. Size must not exceed getLeMaximumAdvertisingDataLength(). If the advertisement is connectable, three bytes will be added for flags.

scanResponse AdvertiseData: Scan response associated with the advertisement data. Size must not exceed getLeMaximumAdvertisingDataLength()

periodicParameters PeriodicAdvertisingParameters: Periodic advertisng parameters. If null, periodic advertising will not be started.

periodicData AdvertiseData: Periodic advertising data. Size must not exceed getLeMaximumAdvertisingDataLength()

duration int: advertising duration, in 10ms unit. Valid range is from 1 (10ms) to 65535 (655,350 ms). 0 means advertising should continue until stopped.

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. 0 means no maximum.

callback AdvertisingSetCallback: Callback for advertising set.

handler Handler: Thread upon which the callbacks will be invoked.

Throws
IllegalArgumentException When any of the data parameter exceed the maximum allowable size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising feature is made when it's not supported by the controller, or when maxExtendedAdvertisingEvents is used on a controller that doesn't support the LE Extended Advertising

startAdvertisingSet

added in API level 26
void startAdvertisingSet (AdvertisingSetParameters parameters, 
                AdvertiseData advertiseData, 
                AdvertiseData scanResponse, 
                PeriodicAdvertisingParameters periodicParameters, 
                AdvertiseData periodicData, 
                AdvertisingSetCallback callback)

Creates a new advertising set. If operation succeed, device will start advertising. This method returns immediately, the operation status is delivered through callback.onAdvertisingSetStarted().

Parameters
parameters AdvertisingSetParameters: advertising set parameters.

advertiseData AdvertiseData: Advertisement data to be broadcasted. Size must not exceed getLeMaximumAdvertisingDataLength(). If the advertisement is connectable, three bytes will be added for flags.

scanResponse AdvertiseData: Scan response associated with the advertisement data. Size must not exceed getLeMaximumAdvertisingDataLength().

periodicParameters PeriodicAdvertisingParameters: periodic advertisng parameters. If null, periodic advertising will not be started.

periodicData AdvertiseData: Periodic advertising data. Size must not exceed getLeMaximumAdvertisingDataLength().

callback AdvertisingSetCallback: Callback for advertising set.

Throws
IllegalArgumentException when any of the data parameter exceed the maximum allowable size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising feature is made when it's not supported by the controller.

startAdvertisingSet

added in API level 26
void startAdvertisingSet (AdvertisingSetParameters parameters, 
                AdvertiseData advertiseData, 
                AdvertiseData scanResponse, 
                PeriodicAdvertisingParameters periodicParameters, 
                AdvertiseData periodicData, 
                AdvertisingSetCallback callback, 
                Handler handler)

Creates a new advertising set. If operation succeed, device will start advertising. This method returns immediately, the operation status is delivered through callback.onAdvertisingSetStarted().

Parameters
parameters AdvertisingSetParameters: advertising set parameters.

advertiseData AdvertiseData: Advertisement data to be broadcasted. Size must not exceed getLeMaximumAdvertisingDataLength(). If the advertisement is connectable, three bytes will be added for flags.

scanResponse AdvertiseData: Scan response associated with the advertisement data. Size must not exceed getLeMaximumAdvertisingDataLength().

periodicParameters PeriodicAdvertisingParameters: periodic advertisng parameters. If null, periodic advertising will not be started.

periodicData AdvertiseData: Periodic advertising data. Size must not exceed getLeMaximumAdvertisingDataLength().

callback AdvertisingSetCallback: Callback for advertising set.

handler Handler: thread upon which the callbacks will be invoked.

Throws
IllegalArgumentException when any of the data parameter exceed the maximum allowable size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising feature is made when it's not supported by the controller.

stopAdvertising

added in API level 21
void stopAdvertising (AdvertiseCallback callback)

Stop Bluetooth LE advertising. The callback must be the same one use in startAdvertising(AdvertiseSettings, AdvertiseData, AdvertiseCallback).

Requires BLUETOOTH_ADMIN permission.

Parameters
callback AdvertiseCallback: AdvertiseCallback identifies the advertising instance to stop.

stopAdvertisingSet

added in API level 26
void stopAdvertisingSet (AdvertisingSetCallback callback)

Used to dispose of a AdvertisingSet object, obtained with startAdvertisingSet(AdvertisingSetParameters, AdvertiseData, AdvertiseData, PeriodicAdvertisingParameters, AdvertiseData, AdvertisingSetCallback).

Parameters
callback AdvertisingSetCallback

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.