Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

ScanFilter.Builder

public static final class ScanFilter.Builder
extends Object

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


Builder class for ScanFilter.

Summary

Public constructors

ScanFilter.Builder()

Public methods

ScanFilter build()

Build ScanFilter.

ScanFilter.Builder setDeviceAddress(String deviceAddress)

Set filter on device address.

ScanFilter.Builder setDeviceName(String deviceName)

Set filter on device name.

ScanFilter.Builder setManufacturerData(int manufacturerId, byte[] manufacturerData)

Set filter on on manufacturerData.

ScanFilter.Builder setManufacturerData(int manufacturerId, byte[] manufacturerData, byte[] manufacturerDataMask)

Set filter on partial manufacture data.

ScanFilter.Builder setServiceData(ParcelUuid serviceDataUuid, byte[] serviceData)

Set filtering on service data.

ScanFilter.Builder setServiceData(ParcelUuid serviceDataUuid, byte[] serviceData, byte[] serviceDataMask)

Set partial filter on service data.

ScanFilter.Builder setServiceUuid(ParcelUuid serviceUuid, ParcelUuid uuidMask)

Set filter on partial service uuid.

ScanFilter.Builder setServiceUuid(ParcelUuid serviceUuid)

Set filter on service uuid.

Inherited methods

Public constructors

ScanFilter.Builder

added in API level 21
public ScanFilter.Builder ()

Public methods

build

added in API level 21
public ScanFilter build ()

Build ScanFilter.

Returns
ScanFilter

Throws
IllegalArgumentException If the filter cannot be built.

setDeviceAddress

added in API level 21
public ScanFilter.Builder setDeviceAddress (String deviceAddress)

Set filter on device address.

Parameters
deviceAddress String: The device Bluetooth address for the filter. It needs to be in the format of "01:02:03:AB:CD:EF". The device address can be validated using BluetoothAdapter.checkBluetoothAddress(String).

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If the deviceAddress is invalid.

setDeviceName

added in API level 21
public ScanFilter.Builder setDeviceName (String deviceName)

Set filter on device name.

Parameters
deviceName String

Returns
ScanFilter.Builder

setManufacturerData

added in API level 21
public ScanFilter.Builder setManufacturerData (int manufacturerId, 
                byte[] manufacturerData)

Set filter on on manufacturerData. A negative manufacturerId is considered as invalid id.

Note the first two bytes of the manufacturerData is the manufacturerId.

Parameters
manufacturerId int

manufacturerData byte

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If the manufacturerId is invalid.

setManufacturerData

added in API level 21
public ScanFilter.Builder setManufacturerData (int manufacturerId, 
                byte[] manufacturerData, 
                byte[] manufacturerDataMask)

Set filter on partial manufacture data. For any bit in the mask, set it the 1 if it needs to match the one in manufacturer data, otherwise set it to 0.

The manufacturerDataMask must have the same length of manufacturerData.

Parameters
manufacturerId int

manufacturerData byte

manufacturerDataMask byte

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If the manufacturerId is invalid, or manufacturerData is null while manufacturerDataMask is not, or manufacturerData and manufacturerDataMask have different length.

setServiceData

added in API level 21
public ScanFilter.Builder setServiceData (ParcelUuid serviceDataUuid, 
                byte[] serviceData)

Set filtering on service data.

Parameters
serviceDataUuid ParcelUuid

serviceData byte

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If serviceDataUuid is null.

setServiceData

added in API level 21
public ScanFilter.Builder setServiceData (ParcelUuid serviceDataUuid, 
                byte[] serviceData, 
                byte[] serviceDataMask)

Set partial filter on service data. For any bit in the mask, set it to 1 if it needs to match the one in service data, otherwise set it to 0 to ignore that bit.

The serviceDataMask must have the same length of the serviceData.

Parameters
serviceDataUuid ParcelUuid

serviceData byte

serviceDataMask byte

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If serviceDataUuid is null or serviceDataMask is null while serviceData is not or serviceDataMask and serviceData has different length.

setServiceUuid

added in API level 21
public ScanFilter.Builder setServiceUuid (ParcelUuid serviceUuid, 
                ParcelUuid uuidMask)

Set filter on partial service uuid. The uuidMask is the bit mask for the serviceUuid. Set any bit in the mask to 1 to indicate a match is needed for the bit in serviceUuid, and 0 to ignore that bit.

Parameters
serviceUuid ParcelUuid

uuidMask ParcelUuid

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If serviceUuid is null but uuidMask is not null.

setServiceUuid

added in API level 21
public ScanFilter.Builder setServiceUuid (ParcelUuid serviceUuid)

Set filter on service uuid.

Parameters
serviceUuid ParcelUuid

Returns
ScanFilter.Builder