public final class DeviceFilter

  1. Object
  2. DeviceFilter

Narrows what the system device chooser offers the user.

A request with no filter shows everything the radios can see, which is a long and confusing list; a request with one good filter usually shows exactly the accessory the user is holding. Filters within one AssociationRequest are OR-combined – a device matching any of them is offered.

AssociationRequest req = new AssociationRequest.Builder()
        .addFilter(DeviceFilter.bleService("180D"))     // heart rate
        .addFilter(DeviceFilter.namePattern("Acme.*"))
        .build();

Fields

public static final int KIND_BLE_SERVICE = 0Filter kind: match a BLE service UUID being advertised.
public static final int KIND_NAME_PATTERN = 1Filter kind: match the advertised device name against a regular expression.
public static final int KIND_ADDRESS = 2Filter kind: match one exact device address.
public static final int KIND_WIFI_SSID = 3Filter kind: match a Wi-Fi SSID.

Methods

public static DeviceFilter bleService(String serviceUuid)Offers only devices advertising the given BLE service.
public static DeviceFilter namePattern(String pattern)Offers only devices whose advertised name matches a regular expression.
public static DeviceFilter address(String address)Offers only the device at one exact address – the reconnect case, where the app already knows which device it wants.
public static DeviceFilter wifiSsid(String ssid)Offers only the Wi-Fi network with the given SSID.
public int getKind()Which of the KIND_ constants this filter is.
public String getValue()The UUID, pattern, address or SSID, depending on getKind().
public String toString()Returns a string representation of the object.

Inherited methods

Field details

KIND_BLE_SERVICE

public static final int KIND_BLE_SERVICE = 0
Filter kind: match a BLE service UUID being advertised.

KIND_NAME_PATTERN

public static final int KIND_NAME_PATTERN = 1
Filter kind: match the advertised device name against a regular expression.

KIND_ADDRESS

public static final int KIND_ADDRESS = 2
Filter kind: match one exact device address.

KIND_WIFI_SSID

public static final int KIND_WIFI_SSID = 3
Filter kind: match a Wi-Fi SSID.

Method details

bleService

public static DeviceFilter bleService(String serviceUuid)
Offers only devices advertising the given BLE service.

Parameters

serviceUuid String
the service UUID, in either the 16-bit short form ("180D") or the full 128-bit form

Returns

the filter

namePattern

public static DeviceFilter namePattern(String pattern)

Offers only devices whose advertised name matches a regular expression.

The pattern is passed through to the platform, which on Android is java.util.regex and on iOS is a substring match on the accessory name – so keep patterns simple if the app runs on both.

Parameters

pattern String
the pattern to match the name against

Returns

the filter

address

public static DeviceFilter address(String address)
Offers only the device at one exact address – the reconnect case, where the app already knows which device it wants.

Parameters

address String
the device address, as com.codename1.bluetooth.BluetoothDevice#getAddress() reports it

Returns

the filter

wifiSsid

public static DeviceFilter wifiSsid(String ssid)
Offers only the Wi-Fi network with the given SSID. Android only; ignored on platforms that associate Bluetooth accessories alone.

Parameters

ssid String
the network name

Returns

the filter

getKind

public int getKind()
Which of the KIND_ constants this filter is.

getValue

public String getValue()
The UUID, pattern, address or SSID, depending on getKind().

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())