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

Builder()

Public methods

ScanFilter build()

Build ScanFilter.

ScanFilter.Builder setAdvertisingDataType(int advertisingDataType)

Set filter on advertising data with specific advertising data type.

ScanFilter.Builder setAdvertisingDataTypeWithData(int advertisingDataType, byte[] advertisingData, byte[] advertisingDataMask)

Set filter on advertising data with specific advertising data type.

ScanFilter.Builder setDeviceAddress(String deviceAddress)

Set a scan filter on the remote device address.

ScanFilter.Builder setDeviceName(String deviceName)

Set filter on device name.

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

Set filter on partial manufacture data.

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

Set filter on on manufacturerData.

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

Set partial filter on service data.

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

Set filtering on service data.

ScanFilter.Builder setServiceSolicitationUuid(ParcelUuid serviceSolicitationUuid, ParcelUuid solicitationUuidMask)

Set filter on partial service Solicitation uuid.

ScanFilter.Builder setServiceSolicitationUuid(ParcelUuid serviceSolicitationUuid)

Set filter on service solicitation uuid.

ScanFilter.Builder setServiceUuid(ParcelUuid serviceUuid)

Set filter on service uuid.

ScanFilter.Builder setServiceUuid(ParcelUuid serviceUuid, ParcelUuid uuidMask)

Set filter on partial service uuid.

Inherited methods

Public constructors

Builder

Added in API level 21
public Builder ()

Public methods

build

Added in API level 21
public ScanFilter build ()

Build ScanFilter.

Returns
ScanFilter

Throws
IllegalArgumentException If the filter cannot be built.

setAdvertisingDataType

Added in API level 33
public ScanFilter.Builder setAdvertisingDataType (int advertisingDataType)

Set filter on advertising data with specific advertising data type.

The values of advertisingDataType are assigned by Bluetooth SIG. For more details refer to Bluetooth Generic Access Profile. (https://www.bluetooth.com/specifications/assigned-numbers/)

Parameters
advertisingDataType int: Value is ScanRecord.DATA_TYPE_FLAGS, ScanRecord.DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL, ScanRecord.DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE, ScanRecord.DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL, ScanRecord.DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE, ScanRecord.DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL, ScanRecord.DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE, ScanRecord.DATA_TYPE_LOCAL_NAME_SHORT, ScanRecord.DATA_TYPE_LOCAL_NAME_COMPLETE, ScanRecord.DATA_TYPE_TX_POWER_LEVEL, ScanRecord.DATA_TYPE_CLASS_OF_DEVICE, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_HASH_C, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R, ScanRecord.DATA_TYPE_DEVICE_ID, ScanRecord.DATA_TYPE_SECURITY_MANAGER_OUT_OF_BAND_FLAGS, ScanRecord.DATA_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE, ScanRecord.DATA_TYPE_SERVICE_SOLICITATION_UUIDS_16_BIT, ScanRecord.DATA_TYPE_SERVICE_SOLICITATION_UUIDS_128_BIT, ScanRecord.DATA_TYPE_SERVICE_DATA_16_BIT, ScanRecord.DATA_TYPE_PUBLIC_TARGET_ADDRESS, ScanRecord.DATA_TYPE_RANDOM_TARGET_ADDRESS, ScanRecord.DATA_TYPE_APPEARANCE, ScanRecord.DATA_TYPE_ADVERTISING_INTERVAL, ScanRecord.DATA_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS, ScanRecord.DATA_TYPE_LE_ROLE, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_HASH_C_256, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R_256, ScanRecord.DATA_TYPE_SERVICE_SOLICITATION_UUIDS_32_BIT, ScanRecord.DATA_TYPE_SERVICE_DATA_32_BIT, ScanRecord.DATA_TYPE_SERVICE_DATA_128_BIT, ScanRecord.DATA_TYPE_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE, ScanRecord.DATA_TYPE_LE_SECURE_CONNECTIONS_RANDOM_VALUE, ScanRecord.DATA_TYPE_URI, ScanRecord.DATA_TYPE_INDOOR_POSITIONING, ScanRecord.DATA_TYPE_TRANSPORT_DISCOVERY_DATA, ScanRecord.DATA_TYPE_LE_SUPPORTED_FEATURES, ScanRecord.DATA_TYPE_CHANNEL_MAP_UPDATE_INDICATION, ScanRecord.DATA_TYPE_PB_ADV, ScanRecord.DATA_TYPE_MESH_MESSAGE, ScanRecord.DATA_TYPE_MESH_BEACON, ScanRecord.DATA_TYPE_BIG_INFO, ScanRecord.DATA_TYPE_BROADCAST_CODE, ScanRecord.DATA_TYPE_RESOLVABLE_SET_IDENTIFIER, ScanRecord.DATA_TYPE_ADVERTISING_INTERVAL_LONG, ScanRecord.DATA_TYPE_3D_INFORMATION_DATA, or ScanRecord.DATA_TYPE_MANUFACTURER_SPECIFIC_DATA

Returns
ScanFilter.Builder This value cannot be null.

Throws
IllegalArgumentException If the advertisingDataType is invalid

setAdvertisingDataTypeWithData

Added in API level 33
public ScanFilter.Builder setAdvertisingDataTypeWithData (int advertisingDataType, 
                byte[] advertisingData, 
                byte[] advertisingDataMask)

Set filter on advertising data with specific advertising data type. For any bit in the mask, set it the 1 if it needs to match the one in advertising data, otherwise set it to 0.

The values of advertisingDataType are assigned by Bluetooth SIG. For more details refer to Bluetooth Generic Access Profile. (https://www.bluetooth.com/specifications/assigned-numbers/) The advertisingDataMask must have the same length of advertisingData.

Parameters
advertisingDataType int: Value is ScanRecord.DATA_TYPE_FLAGS, ScanRecord.DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL, ScanRecord.DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE, ScanRecord.DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL, ScanRecord.DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE, ScanRecord.DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL, ScanRecord.DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE, ScanRecord.DATA_TYPE_LOCAL_NAME_SHORT, ScanRecord.DATA_TYPE_LOCAL_NAME_COMPLETE, ScanRecord.DATA_TYPE_TX_POWER_LEVEL, ScanRecord.DATA_TYPE_CLASS_OF_DEVICE, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_HASH_C, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R, ScanRecord.DATA_TYPE_DEVICE_ID, ScanRecord.DATA_TYPE_SECURITY_MANAGER_OUT_OF_BAND_FLAGS, ScanRecord.DATA_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE, ScanRecord.DATA_TYPE_SERVICE_SOLICITATION_UUIDS_16_BIT, ScanRecord.DATA_TYPE_SERVICE_SOLICITATION_UUIDS_128_BIT, ScanRecord.DATA_TYPE_SERVICE_DATA_16_BIT, ScanRecord.DATA_TYPE_PUBLIC_TARGET_ADDRESS, ScanRecord.DATA_TYPE_RANDOM_TARGET_ADDRESS, ScanRecord.DATA_TYPE_APPEARANCE, ScanRecord.DATA_TYPE_ADVERTISING_INTERVAL, ScanRecord.DATA_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS, ScanRecord.DATA_TYPE_LE_ROLE, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_HASH_C_256, ScanRecord.DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R_256, ScanRecord.DATA_TYPE_SERVICE_SOLICITATION_UUIDS_32_BIT, ScanRecord.DATA_TYPE_SERVICE_DATA_32_BIT, ScanRecord.DATA_TYPE_SERVICE_DATA_128_BIT, ScanRecord.DATA_TYPE_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE, ScanRecord.DATA_TYPE_LE_SECURE_CONNECTIONS_RANDOM_VALUE, ScanRecord.DATA_TYPE_URI, ScanRecord.DATA_TYPE_INDOOR_POSITIONING, ScanRecord.DATA_TYPE_TRANSPORT_DISCOVERY_DATA, ScanRecord.DATA_TYPE_LE_SUPPORTED_FEATURES, ScanRecord.DATA_TYPE_CHANNEL_MAP_UPDATE_INDICATION, ScanRecord.DATA_TYPE_PB_ADV, ScanRecord.DATA_TYPE_MESH_MESSAGE, ScanRecord.DATA_TYPE_MESH_BEACON, ScanRecord.DATA_TYPE_BIG_INFO, ScanRecord.DATA_TYPE_BROADCAST_CODE, ScanRecord.DATA_TYPE_RESOLVABLE_SET_IDENTIFIER, ScanRecord.DATA_TYPE_ADVERTISING_INTERVAL_LONG, ScanRecord.DATA_TYPE_3D_INFORMATION_DATA, or ScanRecord.DATA_TYPE_MANUFACTURER_SPECIFIC_DATA

advertisingData byte: This value cannot be null.

advertisingDataMask byte: This value cannot be null.

Returns
ScanFilter.Builder This value cannot be null.

Throws
IllegalArgumentException If the advertisingDataType is invalid, advertisingData or advertisingDataMask is null or advertisingData and advertisingDataMask have different length.

setDeviceAddress

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

Set a scan filter on the remote device address.

The address passed to this API must be in big endian byte order. It needs to be in the format of "01:02:03:AB:CD:EF". The device address can be validated using BluetoothAdapter.checkBluetoothAddress(String). The @AddressType is defaulted to BluetoothDevice.ADDRESS_TYPE_PUBLIC.

Parameters
deviceAddress String: the remote device Bluetooth address for the filter

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, 
                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.

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.

Parameters
manufacturerId int

manufacturerData byte

Returns
ScanFilter.Builder

Throws
IllegalArgumentException If the manufacturerId is invalid.

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.

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.

setServiceSolicitationUuid

Added in API level 29
public ScanFilter.Builder setServiceSolicitationUuid (ParcelUuid serviceSolicitationUuid, 
                ParcelUuid solicitationUuidMask)

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

Parameters
serviceSolicitationUuid ParcelUuid: can only be null if solicitationUuidMask is null.

solicitationUuidMask ParcelUuid: can be null or a mask with no restriction.

Returns
ScanFilter.Builder This value cannot be null.

Throws
IllegalArgumentException If serviceSolicitationUuid is null but solicitationUuidMask is not null.

setServiceSolicitationUuid

Added in API level 29
public ScanFilter.Builder setServiceSolicitationUuid (ParcelUuid serviceSolicitationUuid)

Set filter on service solicitation uuid.

Parameters
serviceSolicitationUuid ParcelUuid: This value may be null.

Returns
ScanFilter.Builder This value cannot be null.

setServiceUuid

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

Set filter on service uuid.

Parameters
serviceUuid ParcelUuid

Returns
ScanFilter.Builder

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.