Code example for NsdServiceInfo

Methods: setPort, setServiceName, setServiceType

0
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void registerService(int port) {
        // Create the NsdServiceInfo object, and populate it. 
        bListening = true;
        initializeRegistrationListener(); 
        NsdServiceInfo serviceInfo = new NsdServiceInfo();
 
        // The name is subject to change based on conflicts 
        // with other services advertised on the same network. 
        serviceInfo.setServiceName(SERVICE_NAME);
        serviceInfo.setServiceType(SERVICE_TYPE);
        serviceInfo.setPort(port);
 
        mNsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD,
                mRegistrationListener);
    } 
 
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void discoverService() { 
        bDiscoverying = true;
        initializeDiscoveryListener();