Added in API level 21

Builder


class Builder
kotlin.Any
   ↳ android.bluetooth.le.ScanFilter.Builder

Builder class for ScanFilter.

Summary

Public constructors

Public methods
ScanFilter!

Build ScanFilter.

ScanFilter.Builder
setAdvertisingDataType(advertisingDataType: Int)

Set filter on advertising data with specific advertising data type.

ScanFilter.Builder
setAdvertisingDataTypeWithData(advertisingDataType: Int, advertisingData: ByteArray, advertisingDataMask: ByteArray)

Set filter on advertising data with specific advertising data type.

ScanFilter.Builder!
setDeviceAddress(deviceAddress: String!)

Set a scan filter on the remote device address.

ScanFilter.Builder!
setDeviceName(deviceName: String!)

Set filter on device name.

ScanFilter.Builder!
setManufacturerData(manufacturerId: Int, manufacturerData: ByteArray!)

Set filter on on manufacturerData.

ScanFilter.Builder!
setManufacturerData(manufacturerId: Int, manufacturerData: ByteArray!, manufacturerDataMask: ByteArray!)

Set filter on partial manufacture data.

ScanFilter.Builder!
setServiceData(serviceDataUuid: ParcelUuid!, serviceData: ByteArray!)

Set filtering on service data.

ScanFilter.Builder!
setServiceData(serviceDataUuid: ParcelUuid!, serviceData: ByteArray!, serviceDataMask: ByteArray!)

Set partial filter on service data.

ScanFilter.Builder
setServiceSolicitationUuid(serviceSolicitationUuid: ParcelUuid?)

Set filter on service solicitation uuid.

ScanFilter.Builder
setServiceSolicitationUuid(serviceSolicitationUuid: ParcelUuid?, solicitationUuidMask: ParcelUuid?)

Set filter on partial service Solicitation uuid.

ScanFilter.Builder!
setServiceUuid(serviceUuid: ParcelUuid!)

Set filter on service uuid.

ScanFilter.Builder!
setServiceUuid(serviceUuid: ParcelUuid!, uuidMask: ParcelUuid!)

Set filter on partial service uuid.

Public constructors

Builder

Added in API level 21
Builder()

Public methods

build

Added in API level 21
fun build(): ScanFilter!

Build ScanFilter.

Exceptions
java.lang.IllegalArgumentException If the filter cannot be built.

setAdvertisingDataType

Added in API level 33
fun setAdvertisingDataType(advertisingDataType: Int): ScanFilter.Builder

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 android.bluetooth.le.ScanRecord#DATA_TYPE_FLAGS, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_LOCAL_NAME_SHORT, android.bluetooth.le.ScanRecord#DATA_TYPE_LOCAL_NAME_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_TX_POWER_LEVEL, android.bluetooth.le.ScanRecord#DATA_TYPE_CLASS_OF_DEVICE, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_HASH_C, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R, android.bluetooth.le.ScanRecord#DATA_TYPE_DEVICE_ID, android.bluetooth.le.ScanRecord#DATA_TYPE_SECURITY_MANAGER_OUT_OF_BAND_FLAGS, android.bluetooth.le.ScanRecord#DATA_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_SOLICITATION_UUIDS_16_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_SOLICITATION_UUIDS_128_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_DATA_16_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_PUBLIC_TARGET_ADDRESS, android.bluetooth.le.ScanRecord#DATA_TYPE_RANDOM_TARGET_ADDRESS, android.bluetooth.le.ScanRecord#DATA_TYPE_APPEARANCE, android.bluetooth.le.ScanRecord#DATA_TYPE_ADVERTISING_INTERVAL, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_ROLE, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_HASH_C_256, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R_256, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_SOLICITATION_UUIDS_32_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_DATA_32_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_DATA_128_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_SECURE_CONNECTIONS_RANDOM_VALUE, android.bluetooth.le.ScanRecord#DATA_TYPE_URI, android.bluetooth.le.ScanRecord#DATA_TYPE_INDOOR_POSITIONING, android.bluetooth.le.ScanRecord#DATA_TYPE_TRANSPORT_DISCOVERY_DATA, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_SUPPORTED_FEATURES, android.bluetooth.le.ScanRecord#DATA_TYPE_CHANNEL_MAP_UPDATE_INDICATION, android.bluetooth.le.ScanRecord#DATA_TYPE_PB_ADV, android.bluetooth.le.ScanRecord#DATA_TYPE_MESH_MESSAGE, android.bluetooth.le.ScanRecord#DATA_TYPE_MESH_BEACON, android.bluetooth.le.ScanRecord#DATA_TYPE_BIG_INFO, android.bluetooth.le.ScanRecord#DATA_TYPE_BROADCAST_CODE, android.bluetooth.le.ScanRecord#DATA_TYPE_RESOLVABLE_SET_IDENTIFIER, android.bluetooth.le.ScanRecord#DATA_TYPE_ADVERTISING_INTERVAL_LONG, android.bluetooth.le.ScanRecord#DATA_TYPE_3D_INFORMATION_DATA, or android.bluetooth.le.ScanRecord#DATA_TYPE_MANUFACTURER_SPECIFIC_DATA
Return
ScanFilter.Builder This value cannot be null.
Exceptions
java.lang.IllegalArgumentException If the advertisingDataType is invalid

setAdvertisingDataTypeWithData

Added in API level 33
fun setAdvertisingDataTypeWithData(
    advertisingDataType: Int,
    advertisingData: ByteArray,
    advertisingDataMask: ByteArray
): ScanFilter.Builder

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 android.bluetooth.le.ScanRecord#DATA_TYPE_FLAGS, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_LOCAL_NAME_SHORT, android.bluetooth.le.ScanRecord#DATA_TYPE_LOCAL_NAME_COMPLETE, android.bluetooth.le.ScanRecord#DATA_TYPE_TX_POWER_LEVEL, android.bluetooth.le.ScanRecord#DATA_TYPE_CLASS_OF_DEVICE, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_HASH_C, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R, android.bluetooth.le.ScanRecord#DATA_TYPE_DEVICE_ID, android.bluetooth.le.ScanRecord#DATA_TYPE_SECURITY_MANAGER_OUT_OF_BAND_FLAGS, android.bluetooth.le.ScanRecord#DATA_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_SOLICITATION_UUIDS_16_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_SOLICITATION_UUIDS_128_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_DATA_16_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_PUBLIC_TARGET_ADDRESS, android.bluetooth.le.ScanRecord#DATA_TYPE_RANDOM_TARGET_ADDRESS, android.bluetooth.le.ScanRecord#DATA_TYPE_APPEARANCE, android.bluetooth.le.ScanRecord#DATA_TYPE_ADVERTISING_INTERVAL, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_ROLE, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_HASH_C_256, android.bluetooth.le.ScanRecord#DATA_TYPE_SIMPLE_PAIRING_RANDOMIZER_R_256, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_SOLICITATION_UUIDS_32_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_DATA_32_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_SERVICE_DATA_128_BIT, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_SECURE_CONNECTIONS_RANDOM_VALUE, android.bluetooth.le.ScanRecord#DATA_TYPE_URI, android.bluetooth.le.ScanRecord#DATA_TYPE_INDOOR_POSITIONING, android.bluetooth.le.ScanRecord#DATA_TYPE_TRANSPORT_DISCOVERY_DATA, android.bluetooth.le.ScanRecord#DATA_TYPE_LE_SUPPORTED_FEATURES, android.bluetooth.le.ScanRecord#DATA_TYPE_CHANNEL_MAP_UPDATE_INDICATION, android.bluetooth.le.ScanRecord#DATA_TYPE_PB_ADV, android.bluetooth.le.ScanRecord#DATA_TYPE_MESH_MESSAGE, android.bluetooth.le.ScanRecord#DATA_TYPE_MESH_BEACON, android.bluetooth.le.ScanRecord#DATA_TYPE_BIG_INFO, android.bluetooth.le.ScanRecord#DATA_TYPE_BROADCAST_CODE, android.bluetooth.le.ScanRecord#DATA_TYPE_RESOLVABLE_SET_IDENTIFIER, android.bluetooth.le.ScanRecord#DATA_TYPE_ADVERTISING_INTERVAL_LONG, android.bluetooth.le.ScanRecord#DATA_TYPE_3D_INFORMATION_DATA, or android.bluetooth.le.ScanRecord#DATA_TYPE_MANUFACTURER_SPECIFIC_DATA
advertisingData ByteArray: This value cannot be null.
advertisingDataMask ByteArray: This value cannot be null.
Return
ScanFilter.Builder This value cannot be null.
Exceptions
java.lang.IllegalArgumentException If the advertisingDataType is invalid, advertisingData or advertisingDataMask is null or advertisingData and advertisingDataMask have different length.

setDeviceAddress

Added in API level 21
fun setDeviceAddress(deviceAddress: String!): ScanFilter.Builder!

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 android.bluetooth.BluetoothAdapter#checkBluetoothAddress. The @AddressType is defaulted to android.bluetooth.BluetoothDevice#ADDRESS_TYPE_PUBLIC.

Parameters
deviceAddress String!: the remote device Bluetooth address for the filter
Exceptions
java.lang.IllegalArgumentException if the deviceAddress is invalid

setDeviceName

Added in API level 21
fun setDeviceName(deviceName: String!): ScanFilter.Builder!

Set filter on device name.

setManufacturerData

Added in API level 21
fun setManufacturerData(
    manufacturerId: Int,
    manufacturerData: ByteArray!
): ScanFilter.Builder!

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

Exceptions
java.lang.IllegalArgumentException If the manufacturerId is invalid.

setManufacturerData

Added in API level 21
fun setManufacturerData(
    manufacturerId: Int,
    manufacturerData: ByteArray!,
    manufacturerDataMask: ByteArray!
): ScanFilter.Builder!

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.

Exceptions
java.lang.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
fun setServiceData(
    serviceDataUuid: ParcelUuid!,
    serviceData: ByteArray!
): ScanFilter.Builder!

Set filtering on service data.

Exceptions
java.lang.IllegalArgumentException If serviceDataUuid is null.

setServiceData

Added in API level 21
fun setServiceData(
    serviceDataUuid: ParcelUuid!,
    serviceData: ByteArray!,
    serviceDataMask: ByteArray!
): ScanFilter.Builder!

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.

Exceptions
java.lang.IllegalArgumentException If serviceDataUuid is null or serviceDataMask is null while serviceData is not or serviceDataMask and serviceData has different length.

setServiceSolicitationUuid

Added in API level 29
fun setServiceSolicitationUuid(serviceSolicitationUuid: ParcelUuid?): ScanFilter.Builder

Set filter on service solicitation uuid.

Parameters
serviceSolicitationUuid ParcelUuid?: This value may be null.
Return
ScanFilter.Builder This value cannot be null.

setServiceSolicitationUuid

Added in API level 29
fun setServiceSolicitationUuid(
    serviceSolicitationUuid: ParcelUuid?,
    solicitationUuidMask: ParcelUuid?
): ScanFilter.Builder

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.
Return
ScanFilter.Builder This value cannot be null.
Exceptions
java.lang.IllegalArgumentException If serviceSolicitationUuid is null but solicitationUuidMask is not null.

setServiceUuid

Added in API level 21
fun setServiceUuid(serviceUuid: ParcelUuid!): ScanFilter.Builder!

Set filter on service uuid.

setServiceUuid

Added in API level 21
fun setServiceUuid(
    serviceUuid: ParcelUuid!,
    uuidMask: ParcelUuid!
): ScanFilter.Builder!

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.

Exceptions
java.lang.IllegalArgumentException If serviceUuid is null but uuidMask is not null.