List of usage examples for android.net.nsd NsdServiceInfo getServiceType
public String getServiceType()
From source file:org.drulabs.localdash.nsddiscovery.NsdHelper.java
public void initializeDiscoveryListener() { mDiscoveryListener = new NsdManager.DiscoveryListener() { @Override// w ww.j a v a 2 s .c om public void onDiscoveryStarted(String regType) { Log.d(TAG, "Service discovery started"); } @Override public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discovery success" + service); String serviceType = service.getServiceType(); Log.d(TAG, "Service discovery success: " + service.getServiceName()); // For some reason the service type received has an extra dot with it, hence // handling that case boolean isOurService = serviceType.equals(SERVICE_TYPE) || serviceType.equals(SERVICE_TYPE_PLUS_DOT); if (!isOurService) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else if (service.getServiceName().contains(mServiceName)) { Log.d(TAG, "different machines. (" + service.getServiceName() + "-" + mServiceName + ")"); mNsdManager.resolveService(service, mResolveListener); } } @Override public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); if (mService == service) { mService = null; } } @Override public void onDiscoveryStopped(String serviceType) { Log.i(TAG, "Discovery stopped: " + serviceType); } @Override public void onStartDiscoveryFailed(String serviceType, int errorCode) { Log.e(TAG, "Discovery failed: Error code:" + errorCode); } @Override public void onStopDiscoveryFailed(String serviceType, int errorCode) { Log.e(TAG, "Discovery failed: Error code:" + errorCode); } }; }
From source file:ibp.plugin.nsd.NSDHelper.java
private JSONObject NsdServiceInfoToJSON(NsdServiceInfo info) { String name = info.getServiceName(); String type = info.getServiceType(); InetAddress host = info.getHost(); int port = info.getPort(); Map<String, Object> map = new HashMap<String, Object>(); map.put("name", name); map.put("type", type); map.put("address", (host == null) ? "null" : host.getHostAddress()); map.put("port", (host == null) ? 0 : port); JSONObject jsonObj = new JSONObject(map); return jsonObj; }