DiscoveryRequest.Builder
public
static
final
class
DiscoveryRequest.Builder
extends Object
| java.lang.Object | |
| ↳ | android.net.nsd.DiscoveryRequest.Builder |
The builder for creating new DiscoveryRequest objects.
Summary
Public constructors | |
|---|---|
Builder(String serviceType)
Creates a new default |
|
Public methods | |
|---|---|
DiscoveryRequest
|
build()
Creates a new |
DiscoveryRequest.Builder
|
setAttributeFilters(Map<String, PatternMatcher> attributeFilters)
Set filters based on service attributes. |
DiscoveryRequest.Builder
|
setDisplayNameAttribute(String attributeKey)
Set the service attribute to use to display the service in the service picker UI. |
DiscoveryRequest.Builder
|
setFlags(long flags)
Set all the discovery flags. |
DiscoveryRequest.Builder
|
setFlags(long flags, long mask)
Sets the discovery flags. |
DiscoveryRequest.Builder
|
setNetwork(Network network)
Sets the |
DiscoveryRequest.Builder
|
setServiceNameFilter(PatternMatcher serviceNameFilter)
Set the filter to apply to |
DiscoveryRequest.Builder
|
setSubtype(String subtype)
Sets the optional subtype of the services to be discovered. |
Inherited methods | |
|---|---|
Public constructors
Builder
public Builder (String serviceType)
Creates a new default Builder object with given service type.
| Parameters | |
|---|---|
serviceType |
String: This value cannot be null. |
| Throws | |
|---|---|
IllegalArgumentException |
if serviceType is null or an empty
string |
Public methods
build
public DiscoveryRequest build ()
Creates a new DiscoveryRequest object.
| Returns | |
|---|---|
DiscoveryRequest |
This value cannot be null. |
setAttributeFilters
public DiscoveryRequest.Builder setAttributeFilters (Map<String, PatternMatcher> attributeFilters)
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 |
Map: A map of attribute key -> filter for that attribute value.
This value may be null. |
| Returns | |
|---|---|
DiscoveryRequest.Builder |
|
setDisplayNameAttribute
public DiscoveryRequest.Builder setDisplayNameAttribute (String attributeKey)
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. |
| Returns | |
|---|---|
DiscoveryRequest.Builder |
|
setFlags
public DiscoveryRequest.Builder setFlags (long flags)
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:
|
| Returns | |
|---|---|
DiscoveryRequest.Builder |
This value cannot be null. |
See also:
setFlags
public DiscoveryRequest.Builder setFlags (long flags, long mask)
Sets the discovery flags.
Multiple flags may be enabled or disabled by passing the logical OR of the flags.
For example, to set DiscoveryRequest.FLAG_NO_PICKER:
setFlags(FLAG_NO_PICKER, FLAG_NO_PICKER)
To disable DiscoveryRequest.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:
|
| Returns | |
|---|---|
DiscoveryRequest.Builder |
This value cannot be null. |
setNetwork
public DiscoveryRequest.Builder setNetwork (Network network)
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 |
| Returns | |
|---|---|
DiscoveryRequest.Builder |
This value cannot be null. |
setServiceNameFilter
public DiscoveryRequest.Builder setServiceNameFilter (PatternMatcher serviceNameFilter)
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. |
| Returns | |
|---|---|
DiscoveryRequest.Builder |
|
setSubtype
public DiscoveryRequest.Builder setSubtype (String subtype)
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, NsdManager.discoverServices will
fail with ERROR(NsdManager.FAILURE_BAD_PARAMETER/android.net.nsd.NsdManager#FAILURE_BAD_PARAMETER 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 ERROR(/#setServiceType) if a
non-empty subtype is specified by this method.
| Parameters | |
|---|---|
subtype |
String: This value may be null. |
| Returns | |
|---|---|
DiscoveryRequest.Builder |
This value cannot be null. |