Example usage for android.net.nsd NsdServiceInfo getHost

List of usage examples for android.net.nsd NsdServiceInfo getHost

Introduction

In this page you can find the example usage for android.net.nsd NsdServiceInfo getHost.

Prototype

public InetAddress getHost() 

Source Link

Document

Get the host address.

Usage

From source file:de.badaix.snapcast.ServerDialogFragment.java

@Override
public void onClick(View v) {
    NsdHelper.getInstance(getContext()).startListening("_snapcast._tcp.", "Snapcast",
            new NsdHelper.NsdHelperListener() {
                @Override/*  w w w.  jav  a  2 s  .c  o m*/
                public void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        setHost(serviceInfo.getHost().getCanonicalHostName(), serviceInfo.getPort(),
                                serviceInfo.getPort() + 1);
                    }
                }
            });
}

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;
}

From source file:ibp.plugin.nsd.NSDHelper.java

public void resolveInfoByName(String name) {
    int index = 0;
    NsdServiceInfo element = null;
    while (index < mServiceInfoList.size()) {
        if (mServiceInfoList.get(index).getServiceName().equals(name)) {
            element = mServiceInfoList.get(index);
            break;
        }//w  w  w .j a  v a2 s  .  com
        index++;
    }
    if (null != element) {
        if (element.getHost() == null) {
            mNsdManager.resolveService(element, mResolveListener);
        } else {
            //"resolveInfoByName: " + "No Need To Resolve."
            resolveServiceCB.success(NsdServiceInfoToJSON(element));
        }
    }
}

From source file:de.badaix.snapcast.MainActivity.java

@Override
public void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo) {
    Log.d(TAG, "resolved: " + serviceInfo);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setHost(serviceInfo.getHost().getCanonicalHostName(), serviceInfo.getPort(), serviceInfo.getPort() + 1);
        startRemoteControl();//from   w w w . ja  v a  2 s  .  c  o m
    }
    NsdHelper.getInstance(this).stopListening();
}