public final class BluetoothLeAdvertiser
extends Object
java.lang.Object | |
↳ | android.bluetooth.le.BluetoothLeAdvertiser |
此课程提供执行蓝牙LE广告操作的方法,例如启动和停止广告。 广告商可以广播最多31个字节的由AdvertiseData
表示的广告数据。
要获得 BluetoothLeAdvertiser
的实例,请调用 getBluetoothLeAdvertiser()
方法。
注意:这里的大多数方法都需要 BLUETOOTH_ADMIN
权限。
也可以看看:
Public methods |
|
---|---|
void |
startAdvertising(AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseCallback callback) 启动蓝牙LE广告。 |
void |
startAdvertising(AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseData scanResponse, AdvertiseCallback callback) 启动蓝牙LE广告。 |
void |
stopAdvertising(AdvertiseCallback callback) 停止蓝牙LE广告。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
void startAdvertising (AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseCallback callback)
启动蓝牙LE广告。 成功后, advertiseData
将会播出。 立即返回,操作状态通过callback
。
需要 BLUETOOTH_ADMIN
权限。
Parameters | |
---|---|
settings |
AdvertiseSettings : Settings for Bluetooth LE advertising. |
advertiseData |
AdvertiseData : Advertisement data to be broadcasted. |
callback |
AdvertiseCallback : Callback for advertising status. |
void startAdvertising (AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseData scanResponse, AdvertiseCallback callback)
启动蓝牙LE广告。 如果操作成功,将会广播advertiseData
。 扫描设备发送活动扫描请求时将返回scanResponse
。 此方法立即返回,操作状态通过callback
传递。
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. |
void stopAdvertising (AdvertiseCallback callback)
停止蓝牙LE广告。 该callback
必须在同一个使用startAdvertising(AdvertiseSettings, AdvertiseData, AdvertiseCallback)
。
需要 BLUETOOTH_ADMIN
权限。
Parameters | |
---|---|
callback |
AdvertiseCallback : AdvertiseCallback identifies the advertising instance to stop. |