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 |
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 |
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
public static final Creator<NsdServiceInfo> CREATOR
Implement the Parcelable interface
Public constructors
Public methods
describeContents
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
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
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
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
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
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
public String getServiceName ()
Get the service name
Returns | |
---|---|
String |
getServiceType
public String getServiceType ()
Get the service type
Returns | |
---|---|
String |
getSubtypes
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
public void removeAttribute (String key)
Remove an attribute by key
Parameters | |
---|---|
key |
String |
setAttribute
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
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
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
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. |
setServiceName
public void setServiceName (String s)
Set the service name
Parameters | |
---|---|
s |
String |
setServiceType
public void setServiceType (String s)
Set the service type
Parameters | |
---|---|
s |
String |
setSubtypes
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
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |
writeToParcel
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 |