ServiceInfoCallback


interface ServiceInfoCallback
android.net.nsd.NsdManager.ServiceInfoCallback

Callback to listen to service info updates. For use with android.net.nsd.NsdManager#registerServiceInfoCallback to register, and with NsdManager.unregisterServiceInfoCallback to stop listening.

Summary

Public methods
open Unit

Reports that the callback was successfully registered.

abstract Unit

Reports that registering the callback failed with an error.

abstract Unit

Reports that service info updates have stopped.

abstract Unit

Reports when the service that this callback listens to becomes unavailable.

open Unit

Reports when the service that this callback listens to becomes unavailable.

abstract Unit

Reports updated service info.

Public methods

onServiceInfoCallbackRegistered

Added in API level 34
open fun onServiceInfoCallbackRegistered(): Unit

Reports that the callback was successfully registered.

Called on the executor passed to android.net.nsd.NsdManager#registerServiceInfoCallback.

This indicates that onServiceInfoCallbackRegistrationFailed will not be called, and service update callbacks will be sent.

onServiceInfoCallbackRegistrationFailed

abstract fun onServiceInfoCallbackRegistrationFailed(errorCode: Int): Unit

Reports that registering the callback failed with an error. Called on the executor passed to android.net.nsd.NsdManager#registerServiceInfoCallback. onServiceInfoCallbackRegistrationFailed will be called exactly once when the callback could not be registered. No other callback will be sent in that case.

Parameters
errorCode Int: Value is one of the following:

onServiceInfoCallbackUnregistered

abstract fun onServiceInfoCallbackUnregistered(): Unit

Reports that service info updates have stopped. Called on the executor passed to android.net.nsd.NsdManager#registerServiceInfoCallback. A callback unregistration operation will call onServiceInfoCallbackUnregistered once. After this, the callback may be reused.

onServiceLost

abstract fun onServiceLost(): Unit

Reports when the service that this callback listens to becomes unavailable.

Called on the executor passed to android.net.nsd.NsdManager#registerServiceInfoCallback. The service may become available again, in which case onServiceUpdated will be called.

This method is never called if onServiceLost(NsdServiceInfo) is implemented.

When registering through registerServiceInfoCallback(DiscoveryRequest,Executor,ServiceInfoCallback), onServiceLost(NsdServiceInfo) should be used instead, as multiple services may be found and this method does not indicate which one was lost.

Additionally, when registering through registerServiceInfoCallback(NsdServiceInfo,Executor,ServiceInfoCallback), if NsdServiceInfo.getNetwork() is null, the service may be found on multiple networks, so onServiceLost(NsdServiceInfo) should also be preferred as it allows identifying on which network the service was lost.

onServiceLost

open fun onServiceLost(serviceInfo: NsdServiceInfo): Unit

Reports when the service that this callback listens to becomes unavailable.

Called on the executor passed to android.net.nsd.NsdManager#registerServiceInfoCallback. The service may become available again, in which case onServiceUpdated will be called.

This is called every time a service (as per NsdServiceInfo.getServiceName()) is lost on any Network (as per NsdServiceInfo.getNetwork()) on which it was previously discovered. Therefore, this method may be called multiple times for a given service name, if multiple onServiceUpdated(NsdServiceInfo) callbacks were received for that service name on different networks.

Parameters
serviceInfo NsdServiceInfo: The service that was lost.
This value cannot be null.

onServiceUpdated

abstract fun onServiceUpdated(serviceInfo: NsdServiceInfo): Unit

Reports updated service info. Called on the executor passed to android.net.nsd.NsdManager#registerServiceInfoCallback. Any service updates will be notified via this callback until NsdManager.unregisterServiceInfoCallback is called. This will only be called once the service is found, so may never be called if the service is never present.

For each service (as identified by NsdServiceInfo.getServiceName()) and network (as per NsdServiceInfo.getNetwork()), this will be called when the service is first found on the Network, and then every time NsdServiceInfo is updated for that service.

Note the same service name may be found multiple times on different networks, if DiscoveryRequest.getNetwork() (when registered via registerServiceInfoCallback(DiscoveryRequest,Executor,ServiceInfoCallback)) or NsdServiceInfo.getNetwork() (when registered via registerServiceInfoCallback(NsdServiceInfo,Executor,ServiceInfoCallback)) was not specified. The NsdServiceInfo contents may differ in that case; in particular NsdServiceInfo.getHostAddresses() may depend on the network.

Parameters
serviceInfo NsdServiceInfo: This value cannot be null.