当前位置: 首页>>代码示例>>Java>>正文


Java NsdServiceInfo类代码示例

本文整理汇总了Java中android.net.nsd.NsdServiceInfo的典型用法代码示例。如果您正苦于以下问题:Java NsdServiceInfo类的具体用法?Java NsdServiceInfo怎么用?Java NsdServiceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NsdServiceInfo类属于android.net.nsd包,在下文中一共展示了NsdServiceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerService

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
private int registerService(Context context) throws java.io.IOException {

        int port = findOpenSocket();

        // Create the NsdServiceInfo object, and populate it.
        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_DEFAULT);
        serviceInfo.setServiceType(SERVICE_TYPE);
        serviceInfo.setPort(port);

        mNsdManager = (NsdManager)context.getSystemService(Context.NSD_SERVICE);

        if (mRegistrationListener == null)
            initializeRegistrationListener();

        mNsdManager.registerService(
                serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);

        return port;
    }
 
开发者ID:n8fr8,项目名称:LittleBitLouder,代码行数:24,代码来源:NSDSender.java

示例2: onServiceResolved

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
@Override
public void onServiceResolved(final NsdServiceInfo serviceInfo) {
    Log.v(TAG, "service resolved: name= " + serviceInfo.getServiceName());

    final int port = serviceInfo.getPort();
    final String host = serviceInfo.getHost().getHostName();

    synchronized (mUrl) {
        if (serviceInfo.getServiceName().equals("openhab-ssl")) {
            mUrl.set("https://" + host + ":" + port);
        } else if (mUrl.get() == null) {
            mUrl.set("http://" + host + ":" + port);
        }
        mUrl.notifyAll();
    }
}
 
开发者ID:vbier,项目名称:habpanelviewer,代码行数:17,代码来源:ServerDiscovery.java

示例3: initializeResolveListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void initializeResolveListener() {
    mResolveListener = new NsdManager.ResolveListener() {

        @Override
        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.e(TAG, "Resolve failed" + errorCode);
        }

        @Override
        public void onServiceResolved(NsdServiceInfo serviceInfo) {
            Log.e(TAG, "Resolve Succeeded. " + serviceInfo);

            if (serviceInfo.getServiceName().equals(mServiceName)) {
                Log.d(TAG, "Same IP.");
                return;
            }
            mService = serviceInfo;
        }
    };
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:21,代码来源:NsdHelper.java

示例4: initializeRegistrationListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void initializeRegistrationListener() {
    mRegistrationListener = new NsdManager.RegistrationListener() {

        @Override
        public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
            mServiceName = NsdServiceInfo.getServiceName();
            Log.d(TAG, "Service registered: " + mServiceName);
        }

        @Override
        public void onRegistrationFailed(NsdServiceInfo arg0, int arg1) {
            Log.d(TAG, "Service registration failed: " + arg1);
        }

        @Override
        public void onServiceUnregistered(NsdServiceInfo arg0) {
            Log.d(TAG, "Service unregistered: " + arg0.getServiceName());
        }

        @Override
        public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.d(TAG, "Service unregistration failed: " + errorCode);
        }

    };
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:27,代码来源:NsdHelper.java

示例5: initializeResolveListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void initializeResolveListener() {
        mResolveListener = new NsdManager.ResolveListener() {
            @Override
            public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
                Log.e(TAG, "Resolve failed " + errorCode);
                mService = null;
                callCallback(CallbackTypeEnum.ResolveFailed);
            }

            @Override
            public void onServiceResolved(NsdServiceInfo serviceInfo) {
                Log.v(TAG, "Resolve Succeeded. " + serviceInfo);
                if (serviceInfo.getServiceName().equals(mServiceName)) {
//                    Log.d(TAG, "Same IP.");
//                    return;
                }
                mService = serviceInfo;
                callCallback(CallbackTypeEnum.ServiceResolved);
            }
        };
    }
 
开发者ID:ekalyvio,项目名称:CowBit,代码行数:22,代码来源:NsdHelper.java

示例6: initializeResolveListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void initializeResolveListener() {
    mResolveListener = new NsdManager.ResolveListener() {
        @Override
        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.e(TAG, "Resolve failed" + errorCode);
        }

        @Override
        public void onServiceResolved(NsdServiceInfo serviceInfo) {
            Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
            if (serviceInfo.getServiceName().equals(mServiceName)) {
                Log.d(TAG, "Same IP.");
                return;
            }
            mService = serviceInfo;
        }
    };
}
 
开发者ID:MycroftAI,项目名称:Mycroft-Android,代码行数:19,代码来源:NetworkAutoDiscoveryUtil.java

示例7: initializeRegistrationListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void initializeRegistrationListener() {
    mRegistrationListener = new NsdManager.RegistrationListener() {
        @Override
        public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
            mServiceName = NsdServiceInfo.getServiceName();
            Log.d(TAG, "Service registered: " + mServiceName);
        }

        @Override
        public void onRegistrationFailed(NsdServiceInfo arg0, int arg1) {
            Log.d(TAG, "Service registration failed: " + arg1);
        }

        @Override
        public void onServiceUnregistered(NsdServiceInfo arg0) {
            Log.d(TAG, "Service unregistered: " + arg0.getServiceName());
        }

        @Override
        public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.d(TAG, "Service unregistration failed: " + errorCode);
        }
    };
}
 
开发者ID:MycroftAI,项目名称:Mycroft-Android,代码行数:25,代码来源:NetworkAutoDiscoveryUtil.java

示例8: testServiceLost

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void testServiceLost() throws IOException, InterruptedException {
    startDiscoveryOnMainThread();
    mDiscoveryListener.onDiscoveryStarted(SERVICE_TYPE);
    NsdServiceInfo serviceInfo = newNsdServiceInfo("device-1234", "_example._tcp.");
    MDNSDiscover.Result result = new MDNSDiscover.Result();
    when(mMockResolver.resolve(eq("device-1234._example._tcp.local"), anyInt())).thenReturn(result);
    mLatch = new CountDownLatch(1);
    mDiscoveryListener.onServiceFound(serviceInfo);
    mLatch.await();
    Map<String, MDNSDiscover.Result> expectedMap = new HashMap<>();
    expectedMap.put("device-1234._example._tcp.local", result);
    verify(mMockListener).onServicesChanged(eq(expectedMap));
    mLatch = new CountDownLatch(1);
    mDiscoveryListener.onServiceLost(serviceInfo);
    mLatch.await();
    expectedMap.clear();
    verify(mMockListener).onServicesChanged(eq(expectedMap));
    stopDiscoveryOnMainThread();
}
 
开发者ID:youviewtv,项目名称:tinydnssd,代码行数:20,代码来源:DiscoverResolverTest.java

示例9: testNoChangesAfterStop

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
/**
 * Resolve a service but inhibit the callback by having the main thread blocked. Stop the
 * DiscoverResolver as soon as the main thread is unblocked, then check the callback does not
 * occur after being stopped.
 * @throws IOException
 * @throws InterruptedException
 */
public void testNoChangesAfterStop() throws IOException, InterruptedException {
    MDNSDiscover.Result result = new MDNSDiscover.Result();
    when(mMockResolver.resolve(eq("device-1234._example._tcp.local"), anyInt())).thenReturn(result);

    startDiscoveryOnMainThread();
    mDiscoveryListener.onDiscoveryStarted(SERVICE_TYPE);
    NsdServiceInfo serviceInfo = newNsdServiceInfo("device-1234", "_example._tcp.");
    blockMainThread();
    new Handler(Looper.getMainLooper()).post(DISCOVER_STOP); // queue this to happen straight after unblockMainThread()
    mDiscoveryListener.onServiceFound(serviceInfo);
    Thread.sleep(100);  // give the resolver some time
    verify(mMockResolver).resolve(eq("device-1234._example._tcp.local"), anyInt());
    verify(mMockListener, never()).onServicesChanged(anyMap());
    unblockMainThread();
    Thread.sleep(100);
    verify(mMockListener, never()).onServicesChanged(anyMap());
}
 
开发者ID:youviewtv,项目名称:tinydnssd,代码行数:25,代码来源:DiscoverResolverTest.java

示例10: initializeResolveListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
private void initializeResolveListener() {
    mResolveListener = new NsdManager.ResolveListener() {
        @Override
        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.d(TAG, "Resolve failed");
        }

        @Override
        public void onServiceResolved(final NsdServiceInfo serviceInfo) {
            Log.d(TAG, "Service resolved :" + serviceInfo);
            final String hostName = serviceInfo.getHost().getHostName();
            final int port = serviceInfo.getPort();
            final String serviceName = serviceInfo.getServiceName();
            handler.post(new Runnable() {
                @Override
                public void run() {
                    serviceDiscoveryListener.onBonjourServiceDiscovered(hostName, port, serviceName);
                }
            });
        }
    };
}
 
开发者ID:mannaz,项目名称:ahc,代码行数:23,代码来源:BonjourManager.java

示例11: toJSON

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
@TargetApi(16)
public static JSONObject toJSON(final NsdServiceInfo serviceInfo) throws JSONException {
    JSONObject obj = new JSONObject();

    InetAddress host = serviceInfo.getHost();
    if (host != null) {
        obj.put("host", host.getHostName());
    }

    int port = serviceInfo.getPort();
    if (port != 0) {
        obj.put("port", port);
    }

    String serviceName = serviceInfo.getServiceName();
    if (serviceName != null) {
        obj.put("serviceName", serviceName);
    }

    String serviceType = serviceInfo.getServiceType();
    if (serviceType != null) {
        obj.put("serviceType", serviceType);
    }

    return obj;
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:27,代码来源:MulticastDNSManager.java

示例12: onServiceFound

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
@Override
public void onServiceFound(final NsdServiceInfo serviceInfo) {
    Log.d(LOGTAG, "onServiceFound: " + serviceInfo.getServiceName());
    JSONObject json = null;
    try {
        json = NsdMulticastDNSManager.toJSON(serviceInfo);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    GeckoAppShell.sendRequestToGecko(new GeckoRequest("NsdManager:ServiceFound", json) {
        @Override
        public void onResponse(NativeJSObject nativeJSObject) {
            // don't care return value.
        }
    });
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:17,代码来源:MulticastDNSManager.java

示例13: onServiceLost

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
@Override
public void onServiceLost(final NsdServiceInfo serviceInfo) {
    Log.d(LOGTAG, "onServiceLost: " + serviceInfo.getServiceName());
    JSONObject json = null;
    try {
        json = NsdMulticastDNSManager.toJSON(serviceInfo);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    GeckoAppShell.sendRequestToGecko(new GeckoRequest("NsdManager:ServiceLost", json) {
        @Override
        public void onResponse(NativeJSObject nativeJSObject) {
            // don't care return value.
        }
    });
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:17,代码来源:MulticastDNSManager.java

示例14: registerService

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
public void registerService(final int port, final String serviceName, final String serviceType, final Map<String, String> attributes, final EventCallback callback) {
    Log.d(LOGTAG, "registerService: " + serviceName + "." + serviceType + ":" + port);
    synchronized (this) {
        if (mStartCallback != null) {
            throw new RuntimeException("Previous operation is not finished");
        }
        mStartCallback = callback;
    }

    NsdServiceInfo serviceInfo = new NsdServiceInfo();
    serviceInfo.setPort(port);
    serviceInfo.setServiceName(serviceName);
    serviceInfo.setServiceType(serviceType);
    setAttributes(serviceInfo, attributes);
    nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, this);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:17,代码来源:MulticastDNSManager.java

示例15: initializeResolveListener

import android.net.nsd.NsdServiceInfo; //导入依赖的package包/类
private void initializeResolveListener() {
    mResolveListener = new NsdManager.ResolveListener() {

        @Override
        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.e(Constants.TAG, "Resolve failed" + errorCode);
        }

        @Override
        public void onServiceResolved(NsdServiceInfo serviceInfo) {
            mServiceInfo = serviceInfo;

            int port = mServiceInfo.getPort();
            InetAddress host = mServiceInfo.getHost();
            String address = host.getHostAddress();
            Log.d(Constants.TAG, "Resolved address = " + address);

            ServerInfo service = new ServerInfo(address, port);
            mServers.add(service);
        }
    };
}
 
开发者ID:andreldm,项目名称:rcontrol,代码行数:23,代码来源:ServiceFinder.java


注:本文中的android.net.nsd.NsdServiceInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。