Class DeviceFilter

java.lang.Object
com.codename1.nearby.companion.DeviceFilter

public final class DeviceFilter extends Object

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();
  • Field Details

    • KIND_BLE_SERVICE

      public static final int KIND_BLE_SERVICE
      Filter kind: match a BLE service UUID being advertised.
      See Also:
    • KIND_NAME_PATTERN

      public static final int KIND_NAME_PATTERN
      Filter kind: match the advertised device name against a regular expression.
      See Also:
    • KIND_ADDRESS

      public static final int KIND_ADDRESS
      Filter kind: match one exact device address.
      See Also:
    • KIND_WIFI_SSID

      public static final int KIND_WIFI_SSID
      Filter kind: match a Wi-Fi SSID.
      See Also:
  • Method Details

    • bleService

      public static DeviceFilter bleService(String serviceUuid)

      Offers only devices advertising the given BLE service.

      Parameters
      • serviceUuid: 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: 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: 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: 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()
      Description copied from class: Object
      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())
      Overrides:
      toString in class Object