Code example for NsdServiceInfo

Methods: getHost, getPort, getServiceName, getServiceType

0
 
            @Override 
            public void onServiceFound(NsdServiceInfo service) {
                Log.d(TAG, "Service discovery success");
                Log.d(TAG, String.format("%s %s %s %d",
                        service.getServiceName(), service.getServiceType(),
                        service.getHost(), service.getPort()));
                if (!service.getServiceType().contains(SERVICE_TYPE)) {
                    Log.d(TAG,
                            "Unknown Service Type: " + service.getServiceType());
                } else if (service.getServiceName().equals(mServiceName)) {
                    Log.d(TAG, "Same machine: " + mServiceName);
                } else { 
                    mNsdManager.resolveService(service, mResolveListener);
                } 
            } 
 
            @Override 
            public void onServiceLost(NsdServiceInfo service) {
                Log.e(TAG, "service lost" + service);
            }