跳转到相应内容

最常访问

最近访问

navigation

AdvertisingSetParameters.Builder

public static final class AdvertisingSetParameters.Builder
extends Object

java.lang.Object
   ↳ android.bluetooth.le.AdvertisingSetParameters.Builder


Builder class for AdvertisingSetParameters.

Summary

Public constructors

AdvertisingSetParameters.Builder()

Public methods

AdvertisingSetParameters build()

Build the AdvertisingSetParameters object.

AdvertisingSetParameters.Builder setAnonymous(boolean isAnonymous)

Set whether advertiser address should be ommited from all packets.

AdvertisingSetParameters.Builder setConnectable(boolean connectable)

Set whether the advertisement type should be connectable or non-connectable.

AdvertisingSetParameters.Builder setIncludeTxPower(boolean includeTxPower)

Set whether TX power should be included in the extended header.

AdvertisingSetParameters.Builder setInterval(int interval)

Set advertising interval.

AdvertisingSetParameters.Builder setLegacyMode(boolean isLegacy)

When set to true, advertising set will advertise 4.x Spec compliant advertisements.

AdvertisingSetParameters.Builder setPrimaryPhy(int primaryPhy)

Set the primary physical channel used for this advertising set.

AdvertisingSetParameters.Builder setScannable(boolean scannable)

Set whether the advertisement type should be scannable.

AdvertisingSetParameters.Builder setSecondaryPhy(int secondaryPhy)

Set the secondary physical channel used for this advertising set.

AdvertisingSetParameters.Builder setTxPowerLevel(int txPowerLevel)

Set the transmission power level for the advertising.

Inherited methods

Public constructors

AdvertisingSetParameters.Builder

added in API level 26
AdvertisingSetParameters.Builder ()

Public methods

build

added in API level 26
AdvertisingSetParameters build ()

Build the AdvertisingSetParameters object.

Returns
AdvertisingSetParameters

Throws
IllegalStateException if invalid combination of parameters is used.

setAnonymous

added in API level 26
AdvertisingSetParameters.Builder setAnonymous (boolean isAnonymous)

Set whether advertiser address should be ommited from all packets. If this mode is used, periodic advertising can't be enabled for this set. This is used only if legacy mode is not used.

Parameters
isAnonymous boolean: whether anonymous advertising should be used.

Returns
AdvertisingSetParameters.Builder

setConnectable

added in API level 26
AdvertisingSetParameters.Builder setConnectable (boolean connectable)

Set whether the advertisement type should be connectable or non-connectable. Legacy advertisements can be both connectable and scannable. Non-legacy advertisements can be only scannable or only connectable.

Parameters
connectable boolean: Controls whether the advertisement type will be connectable (true) or non-connectable (false).

Returns
AdvertisingSetParameters.Builder

setIncludeTxPower

added in API level 26
AdvertisingSetParameters.Builder setIncludeTxPower (boolean includeTxPower)

Set whether TX power should be included in the extended header. This is used only if legacy mode is not used.

Parameters
includeTxPower boolean: whether TX power should be included in extended header

Returns
AdvertisingSetParameters.Builder

setInterval

added in API level 26
AdvertisingSetParameters.Builder setInterval (int interval)

Set advertising interval.

Parameters
interval int: Bluetooth LE Advertising interval, in 0.625ms unit. Valid range is from 160 (100ms) to 16777215 (10,485.759375 s). Recommended values are: INTERVAL_LOW, INTERVAL_MEDIUM, or INTERVAL_HIGH.

Returns
AdvertisingSetParameters.Builder

Throws
IllegalArgumentException If the interval is invalid.

setLegacyMode

added in API level 26
AdvertisingSetParameters.Builder setLegacyMode (boolean isLegacy)

When set to true, advertising set will advertise 4.x Spec compliant advertisements.

Parameters
isLegacy boolean: whether legacy advertising mode should be used.

Returns
AdvertisingSetParameters.Builder

setPrimaryPhy

added in API level 26
AdvertisingSetParameters.Builder setPrimaryPhy (int primaryPhy)

Set the primary physical channel used for this advertising set. This is used only if legacy mode is not used. Use isLeCodedPhySupported() to determine if LE Coded PHY is supported on this device.

Parameters
primaryPhy int: Primary advertising physical channel, can only be PHY_LE_1M or PHY_LE_CODED.

Returns
AdvertisingSetParameters.Builder

Throws
IllegalArgumentException If the primaryPhy is invalid.

setScannable

added in API level 26
AdvertisingSetParameters.Builder setScannable (boolean scannable)

Set whether the advertisement type should be scannable. Legacy advertisements can be both connectable and scannable. Non-legacy advertisements can be only scannable or only connectable.

Parameters
scannable boolean: Controls whether the advertisement type will be scannable (true) or non-scannable (false).

Returns
AdvertisingSetParameters.Builder

setSecondaryPhy

added in API level 26
AdvertisingSetParameters.Builder setSecondaryPhy (int secondaryPhy)

Set the secondary physical channel used for this advertising set. This is used only if legacy mode is not used. Use isLeCodedPhySupported() and isLe2MPhySupported() to determine if LE Coded PHY or 2M PHY is supported on this device.

Parameters
secondaryPhy int: Secondary advertising physical channel, can only be one of PHY_LE_1M, PHY_LE_2M or PHY_LE_CODED.

Returns
AdvertisingSetParameters.Builder

Throws
IllegalArgumentException If the secondaryPhy is invalid.

setTxPowerLevel

added in API level 26
AdvertisingSetParameters.Builder setTxPowerLevel (int txPowerLevel)

Set the transmission power level for the advertising.

Parameters
txPowerLevel int: Transmission power of Bluetooth LE Advertising, in dBm. The valid range is [-127, 1] Recommended values are: TX_POWER_ULTRA_LOW, TX_POWER_LOW, TX_POWER_MEDIUM, or TX_POWER_HIGH.

Returns
AdvertisingSetParameters.Builder

Throws
IllegalArgumentException If the txPowerLevel is invalid.
此网站会使用 Cookie 来存储您在此网站上指定的语言和显示选项偏好设置。

获取最新的 Android Developers 资讯和提示,助您在 Google Play 上取得成功。

* 必填字段

成功!

在微信上关注 Google Developers

要以浏览此网站吗?

您请求访问的是网页,但是您为此网站设置的语言偏好为

要更改您的语言偏好设置并以浏览此网站吗?如果以后您想要更改语言偏好设置,请使用每个页面底部的语言菜单。

该类需要 或更高的 API 级别

此文档已被隐藏,因为您为该文档选择的 API 级别是 。您可以使用左侧导航栏上方的选择器来更改文档的 API 级别。

要详细了解如何根据您的应用需求指定 API 级别,请参阅支持不同平台版本

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)