Android APIs
public static final class

ScanFilter.Builder

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

Class Overview

Builder class for ScanFilter.

Summary

Public Constructors
ScanFilter.Builder()
Public Methods
ScanFilter build()
Build ScanFilter.
ScanFilter.Builder setMacAddress(String macAddress)
Set filter on device mac address.
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 setName(String localName)
Set filter on local name.
ScanFilter.Builder setRssiRange(int minRssi, int maxRssi)
Set the desired rssi range for the filter.
ScanFilter.Builder setServiceData(byte[] serviceData, byte[] serviceDataMask)
Set partial filter on service data.
ScanFilter.Builder setServiceData(byte[] serviceData)
Set filtering 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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ScanFilter.Builder ()

Public Methods

public ScanFilter build ()

Build ScanFilter.

Throws
IllegalArgumentException If the filter cannot be built.

public ScanFilter.Builder setMacAddress (String macAddress)

Set filter on device mac address.

Parameters
macAddress The device mac address for the filter. It needs to be in the format of "01:02:03:AB:CD:EF". The mac address can be validated using checkBluetoothAddress(String).
Throws
IllegalArgumentException If the macAddress is invalid.

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.

Throws
IllegalArgumentException If the manufacturerId is invalid.

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.

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

public ScanFilter.Builder setName (String localName)

Set filter on local name.

public ScanFilter.Builder setRssiRange (int minRssi, int maxRssi)

Set the desired rssi range for the filter. A scan result with rssi in the range of [minRssi, maxRssi] will be consider as a match.

public ScanFilter.Builder setServiceData (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.

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

public ScanFilter.Builder setServiceData (byte[] serviceData)

Set filtering on service data.

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.

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

public ScanFilter.Builder setServiceUuid (ParcelUuid serviceUuid)

Set filter on service uuid.