NsdServiceInfo


public final class NsdServiceInfo
extends Object implements Parcelable

java.lang.Object
   ↳ android.net.nsd.NsdServiceInfo


A class representing service information for network service discovery

See also:

Summary

Inherited constants

Fields

public static final Creator<NsdServiceInfo> CREATOR

Implement the Parcelable interface

Public constructors

NsdServiceInfo()

Public methods

int describeContents()

Implement the Parcelable interface

Map<String, byte[]> getAttributes()

Retrieve attributes as a map of String keys to byte[] values.

InetAddress getHost()

This method was deprecated in API level Baklava. Use getHostAddresses() to get the entire list of addresses for the host.

List<InetAddress> getHostAddresses()

Get the host addresses.

Network getNetwork()

Get the network where the service can be found.

int getPort()

Get port number.

String getServiceName()

Get the service name

String getServiceType()

Get the service type

Set<String> getSubtypes()

Returns subtypes of this service instance.

void removeAttribute(String key)

Remove an attribute by key

void setAttribute(String key, String value)

Add a service attribute as a key/value pair.

void setHost(InetAddress s)

This method was deprecated in API level Baklava. Use setHostAddresses(java.util.List) to set multiple addresses for the host.

void setHostAddresses(List<InetAddress> addresses)

Set the host addresses.

void setNetwork(Network network)

Set the network where the service can be found.

void setPort(int p)

Set port number

void setServiceName(String s)

Set the service name

void setServiceType(String s)

Set the service type

void setSubtypes(Set<String> subtypes)

Sets the subtypes to be advertised for this service instance.

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel dest, int flags)

Implement the Parcelable interface

Inherited methods

Fields

CREATOR

Added in API level 16
public static final Creator<NsdServiceInfo> CREATOR

Implement the Parcelable interface

Public constructors

NsdServiceInfo

Added in API level 16
public NsdServiceInfo ()

Public methods

describeContents

Added in API level 16
public int describeContents ()

Implement the Parcelable interface

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

getAttributes

Added in API level 21
public Map<String, byte[]> getAttributes ()

Retrieve attributes as a map of String keys to byte[] values. The attributes map is only valid for a resolved service.

The returned map is unmodifiable; changes must be made through setAttribute(String, String) and removeAttribute(String).

Returns
Map<String, byte[]>

getHost

Added in API level 16
Deprecated in API level Baklava
public InetAddress getHost ()

This method was deprecated in API level Baklava.
Use getHostAddresses() to get the entire list of addresses for the host.

Get the host address. The host address is valid for a resolved service.

Returns
InetAddress

getHostAddresses

Added in API level 34
Also in T Extensions 7
public List<InetAddress> getHostAddresses ()

Get the host addresses. All host addresses are valid for the resolved service. All addresses share the same port

Returns
List<InetAddress> This value cannot be null.

See also:

getNetwork

Added in API level 33
Also in T Extensions 3
public Network getNetwork ()

Get the network where the service can be found. This is set if this NsdServiceInfo was obtained from NsdManager.discoverServices or NsdManager.resolveService, unless the service was found on a network interface that does not have a Network (such as a tethering downstream, where services are advertised from devices connected to this device via tethering).

Returns
Network This value may be null.

getPort

Added in API level 16
public int getPort ()

Get port number. The port number is valid for a resolved service. The port is valid for all addresses.

Returns
int

See also:

getServiceName

Added in API level 16
public String getServiceName ()

Get the service name

Returns
String

getServiceType

Added in API level 16
public String getServiceType ()

Get the service type

Returns
String

getSubtypes

Added in API level 35
Also in T Extensions 12
public Set<String> getSubtypes ()

Returns subtypes of this service instance. When this object is returned by the service discovery/browse APIs (etc. NsdManager.DiscoveryListener), the return value may or may not include the subtypes of this service.

Returns
Set<String> This value cannot be null.

removeAttribute

Added in API level 21
public void removeAttribute (String key)

Remove an attribute by key

Parameters
key String

setAttribute

Added in API level 21
public void setAttribute (String key, 
                String value)

Add a service attribute as a key/value pair.

Service attributes are included as DNS-SD TXT record pairs.

The key must be US-ASCII printable characters, excluding the '=' character. Values may be UTF-8 strings or null. The total length of key + value must be less than 255 bytes.

Keys should be short, ideally no more than 9 characters, and unique per instance of NsdServiceInfo. Calling setAttribute(String, String) twice with the same key will overwrite first value.

Parameters
key String

value String

setHost

Added in API level 16
Deprecated in API level Baklava
public void setHost (InetAddress s)

This method was deprecated in API level Baklava.
Use setHostAddresses(java.util.List) to set multiple addresses for the host.

Set the host address

Parameters
s InetAddress

setHostAddresses

Added in API level 34
Also in T Extensions 7
public void setHostAddresses (List<InetAddress> addresses)

Set the host addresses.

When registering hosts/services, there can only be one registration including address records for a given hostname.

For example, if a client registers a service with the hostname "MyHost" and the address records of 192.168.1.1 and 192.168.1.2, then other registrations for the hostname "MyHost" must not have any address record, otherwise there will be a conflict.

Parameters
addresses List: This value cannot be null.

setNetwork

Added in API level 33
Also in T Extensions 3
public void setNetwork (Network network)

Set the network where the service can be found.

Parameters
network Network: The network, or null to search for, or to announce, the service on all connected networks.

setPort

Added in API level 16
public void setPort (int p)

Set port number

Parameters
p int

setServiceName

Added in API level 16
public void setServiceName (String s)

Set the service name

Parameters
s String

setServiceType

Added in API level 16
public void setServiceType (String s)

Set the service type

Parameters
s String

setSubtypes

Added in API level 35
Also in T Extensions 12
public void setSubtypes (Set<String> subtypes)

Sets the subtypes to be advertised for this service instance. The elements in subtypes should be the subtype identifiers which have the trailing "._sub" removed. For example, the subtype should be "_printer" for "_printer._sub._http._tcp.local". Only one subtype will be registered if multiple elements of subtypes have the same case-insensitive value.

Parameters
subtypes Set: This value cannot be null.

toString

Added in API level 16
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.

writeToParcel

Added in API level 16
public void writeToParcel (Parcel dest, 
                int flags)

Implement the Parcelable interface

Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES