Most visited

Recently visited

Added in API level 21

BluetoothLeAdvertiser

public final class BluetoothLeAdvertiser
extends Object

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


此课程提供执行蓝牙LE广告操作的方法,例如启动和停止广告。 广告商可以广播最多31个字节的由AdvertiseData表示的广告数据。

要获得 BluetoothLeAdvertiser的实例,请调用 getBluetoothLeAdvertiser()方法。

注意:这里的大多数方法都需要 BLUETOOTH_ADMIN权限。

也可以看看:

Summary

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

Public methods

startAdvertising

Added in API level 21
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.

startAdvertising

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

启动蓝牙LE广告。 如果操作成功,将会广播advertiseData 扫描设备发送活动扫描请求时将返回scanResponse 此方法立即返回,操作状态通过callback传递。

需要 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.

stopAdvertising

Added in API level 21
void stopAdvertising (AdvertiseCallback callback)

停止蓝牙LE广告。 callback必须在同一个使用startAdvertising(AdvertiseSettings, AdvertiseData, AdvertiseCallback)

需要 BLUETOOTH_ADMIN权限。

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

Hooray!