Builder


class Builder
kotlin.Any
   ↳ android.net.nsd.DiscoveryRequest.Builder

The builder for creating new DiscoveryRequest objects.

Summary

Public constructors
Builder(serviceType: String)

Creates a new default Builder object with given service type.

Public methods
DiscoveryRequest

Creates a new DiscoveryRequest object.

DiscoveryRequest.Builder

Set filters based on service attributes.

DiscoveryRequest.Builder

Set the service attribute to use to display the service in the service picker UI.

DiscoveryRequest.Builder
setFlags(flags: Long)

Set all the discovery flags.

DiscoveryRequest.Builder
setFlags(flags: Long, mask: Long)

Sets the discovery flags.

DiscoveryRequest.Builder
setNetwork(network: Network?)

Sets the Network on which the discovery queries should be sent.

DiscoveryRequest.Builder
setServiceNameFilter(serviceNameFilter: PatternMatcher?)

Set the filter to apply to NsdServiceInfo.getServiceName() on received services.

DiscoveryRequest.Builder
setSubtype(subtype: String?)

Sets the optional subtype of the services to be discovered.

Public constructors

Builder

Builder(serviceType: String)

Creates a new default Builder object with given service type.

Parameters
serviceType String: This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if serviceType is null or an empty string

Public methods

build

fun build(): DiscoveryRequest

Creates a new DiscoveryRequest object.

Return
DiscoveryRequest This value cannot be null.

setAttributeFilters

Added in API level 35
fun setAttributeFilters(attributeFilters: MutableMap<String!, PatternMatcher!>?): DiscoveryRequest.Builder

Set filters based on service attributes.

Service attributes are as per NsdServiceInfo.getAttributes().

Keys of the provided map should match attribute keys. As per RFC6763 6.4. attribute keys are expected to be printable US-ASCII values (0x20-0x7E), and the key matching is not case-sensitive.

Values of the map are matchers that will be checked against attributes value bytes read as uppercase hexadecimal if the pattern starts with 0x, or using UTF-8 encoding if it does not. Value matching is case-sensitive.

If a map value is null, the corresponding attribute will be expected to be a boolean attribute with no value as per RFC6763 6.4.

If a null or empty map is passed, no filtering will be done based on attributes (the default).

Parameters
attributeFilters MutableMap<String!, PatternMatcher!>?: A map of attribute key -> filter for that attribute value.
This value may be null.

setDisplayNameAttribute

Added in API level 35
fun setDisplayNameAttribute(attributeKey: String?): DiscoveryRequest.Builder

Set the service attribute to use to display the service in the service picker UI.

Attribute key matching is not case-sensitive, as per RFC6763 6.4.

Defaults to null, which means the service name will be used instead.

Parameters
attributeKey String?: The key of the attribute, or null to use the service name.

setFlags

Added in API level 35
fun setFlags(flags: Long): DiscoveryRequest.Builder

Set all the discovery flags.

Parameters
flags Long: A bitmask of flags that should be enabled, or 0 to disable all flags.
Value is either 0 or a combination of the following:
Return
DiscoveryRequest.Builder This value cannot be null.

setFlags

Added in API level 35
fun setFlags(
    flags: Long,
    mask: Long
): DiscoveryRequest.Builder

Sets the discovery flags.

Multiple flags may be enabled or disabled by passing the logical OR of the flags.

For example, to set FLAG_NO_PICKER: setFlags(FLAG_NO_PICKER, FLAG_NO_PICKER)

To disable FLAG_NO_PICKER: setFlags(0, FLAG_NO_PICKER)

Parameters
flags Long: a bitmask of values to set; may be a single flag, the logical OR of multiple flags, or 0 to clear.
Value is either 0 or a combination of the following:
mask Long: a bitmask indicating which flags to modify.
Value is either 0 or a combination of the following:
Return
DiscoveryRequest.Builder This value cannot be null.

setNetwork

fun setNetwork(network: Network?): DiscoveryRequest.Builder

Sets the Network on which the discovery queries should be sent.

Parameters
network Network?: the discovery network or null if the query should be sent on all supported networks
Return
DiscoveryRequest.Builder This value cannot be null.

setServiceNameFilter

Added in API level 35
fun setServiceNameFilter(serviceNameFilter: PatternMatcher?): DiscoveryRequest.Builder

Set the filter to apply to NsdServiceInfo.getServiceName() on received services.

As per RFC6335 5.1., service names must be only US-ASCII letters, digits and hyphens, and matching is not case-sensitive.

Defaults to null, which means services will not be filtered by name.

Parameters
serviceNameFilter PatternMatcher?: This value may be null.

setSubtype

fun setSubtype(subtype: String?): DiscoveryRequest.Builder

Sets the optional subtype of the services to be discovered. If a non-empty subtype is specified, it must start with underscore ('_') and have the trailing "._sub" removed. Otherwise, android.net.nsd.NsdManager#discoverServices will fail with android.net.nsd.NsdManager#FAILURE_BAD_PARAMETER. For example, subtype should be "_printer" for DNS name "_printer._sub._http._tcp". In this case, only services with this subtype will be queried, rather than all services of the base service type. Note that a non-empty service type must be specified with #setServiceType if a non-empty subtype is specified by this method.

Parameters
subtype String?: This value may be null.
Return
DiscoveryRequest.Builder This value cannot be null.