Added in API level 21

BluetoothLeAdvertiser

class BluetoothLeAdvertiser
kotlin.Any
   ↳ 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 android.bluetooth.BluetoothAdapter#getBluetoothLeAdvertiser() method.

Summary

Public methods
Unit
startAdvertising(settings: AdvertiseSettings!, advertiseData: AdvertiseData!, callback: AdvertiseCallback!)

Start Bluetooth LE Advertising.

Unit
startAdvertising(settings: AdvertiseSettings!, advertiseData: AdvertiseData!, scanResponse: AdvertiseData!, callback: AdvertiseCallback!)

Start Bluetooth LE Advertising.

Unit
startAdvertisingSet(parameters: AdvertisingSetParameters!, advertiseData: AdvertiseData!, scanResponse: AdvertiseData!, periodicParameters: PeriodicAdvertisingParameters!, periodicData: AdvertiseData!, callback: AdvertisingSetCallback!)

Creates a new advertising set.

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

Creates a new advertising set.

Unit
startAdvertisingSet(parameters: AdvertisingSetParameters!, advertiseData: AdvertiseData!, scanResponse: AdvertiseData!, periodicParameters: PeriodicAdvertisingParameters!, periodicData: AdvertiseData!, duration: Int, maxExtendedAdvertisingEvents: Int, callback: AdvertisingSetCallback!)

Creates a new advertising set.

Unit
startAdvertisingSet(parameters: AdvertisingSetParameters!, advertiseData: AdvertiseData!, scanResponse: AdvertiseData!, periodicParameters: PeriodicAdvertisingParameters!, periodicData: AdvertiseData!, duration: Int, maxExtendedAdvertisingEvents: Int, callback: AdvertisingSetCallback!, handler: Handler!)

Creates a new advertising set.

Unit

Stop Bluetooth LE advertising.

Unit

Used to dispose of a AdvertisingSet object, obtained with android.

Public methods

startAdvertising

Added in API level 21
fun startAdvertising(
    settings: AdvertiseSettings!,
    advertiseData: AdvertiseData!,
    callback: AdvertiseCallback!
): Unit

Start Bluetooth LE Advertising. On success, the advertiseData will be broadcasted. Returns immediately, the operation status is delivered through callback.
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
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
fun startAdvertising(
    settings: AdvertiseSettings!,
    advertiseData: AdvertiseData!,
    scanResponse: AdvertiseData!,
    callback: AdvertiseCallback!
): Unit

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.
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
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
fun startAdvertisingSet(
    parameters: AdvertisingSetParameters!,
    advertiseData: AdvertiseData!,
    scanResponse: AdvertiseData!,
    periodicParameters: PeriodicAdvertisingParameters!,
    periodicData: AdvertiseData!,
    callback: AdvertisingSetCallback!
): Unit

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


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.
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.
scanResponse AdvertiseData!: Scan response associated with the advertisement data. Size must not exceed BluetoothAdapter#getLeMaximumAdvertisingDataLength.
periodicParameters PeriodicAdvertisingParameters!: periodic advertisng parameters. If null, periodic advertising will not be started.
periodicData AdvertiseData!: Periodic advertising data. Size must not exceed android.bluetooth.BluetoothAdapter#getLeMaximumAdvertisingDataLength.
callback AdvertisingSetCallback!: Callback for advertising set.
Exceptions
java.lang.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
fun startAdvertisingSet(
    parameters: AdvertisingSetParameters!,
    advertiseData: AdvertiseData!,
    scanResponse: AdvertiseData!,
    periodicParameters: PeriodicAdvertisingParameters!,
    periodicData: AdvertiseData!,
    callback: AdvertisingSetCallback!,
    handler: Handler!
): Unit

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


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.
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.
scanResponse AdvertiseData!: Scan response associated with the advertisement data. Size must not exceed BluetoothAdapter#getLeMaximumAdvertisingDataLength.
periodicParameters PeriodicAdvertisingParameters!: periodic advertisng parameters. If null, periodic advertising will not be started.
periodicData AdvertiseData!: Periodic advertising data. Size must not exceed android.bluetooth.BluetoothAdapter#getLeMaximumAdvertisingDataLength.
callback AdvertisingSetCallback!: Callback for advertising set.
handler Handler!: thread upon which the callbacks will be invoked.
Exceptions
java.lang.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
fun startAdvertisingSet(
    parameters: AdvertisingSetParameters!,
    advertiseData: AdvertiseData!,
    scanResponse: AdvertiseData!,
    periodicParameters: PeriodicAdvertisingParameters!,
    periodicData: AdvertiseData!,
    duration: Int,
    maxExtendedAdvertisingEvents: Int,
    callback: AdvertisingSetCallback!
): Unit

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


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.
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.
scanResponse AdvertiseData!: Scan response associated with the advertisement data. Size must not exceed BluetoothAdapter#getLeMaximumAdvertisingDataLength.
periodicParameters PeriodicAdvertisingParameters!: periodic advertisng parameters. If null, periodic advertising will not be started.
periodicData AdvertiseData!: Periodic advertising data. Size must not exceed android.bluetooth.BluetoothAdapter#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.
Exceptions
java.lang.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
fun startAdvertisingSet(
    parameters: AdvertisingSetParameters!,
    advertiseData: AdvertiseData!,
    scanResponse: AdvertiseData!,
    periodicParameters: PeriodicAdvertisingParameters!,
    periodicData: AdvertiseData!,
    duration: Int,
    maxExtendedAdvertisingEvents: Int,
    callback: AdvertisingSetCallback!,
    handler: Handler!
): Unit

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


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.
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.
scanResponse AdvertiseData!: Scan response associated with the advertisement data. Size must not exceed BluetoothAdapter#getLeMaximumAdvertisingDataLength
periodicParameters PeriodicAdvertisingParameters!: Periodic advertisng parameters. If null, periodic advertising will not be started.
periodicData AdvertiseData!: Periodic advertising data. Size must not exceed android.bluetooth.BluetoothAdapter#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.
Exceptions
java.lang.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

stopAdvertising

Added in API level 21
fun stopAdvertising(callback: AdvertiseCallback!): Unit

Stop Bluetooth LE advertising. The callback must be the same one use in android.bluetooth.le.BluetoothLeAdvertiser#startAdvertising.
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
callback AdvertiseCallback!: AdvertiseCallback identifies the advertising instance to stop.

stopAdvertisingSet

Added in API level 26
fun stopAdvertisingSet(callback: AdvertisingSetCallback!): Unit

Used to dispose of a AdvertisingSet object, obtained with android.bluetooth.le.BluetoothLeAdvertiser#startAdvertisingSet.
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