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


Java NsdManager.DiscoveryListener方法代码示例

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


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

示例1: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
private void initializeDiscoveryListener(final String serviceType) {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {
        @Override
        public void onStartDiscoveryFailed(String serviceType, int errorCode) {
            Log.d(TAG, "Discovery failed");
        }

        @Override
        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            Log.d(TAG, "Stopping discovery failed");
        }

        @Override
        public void onDiscoveryStarted(String serviceType) {
            Log.d(TAG, "Discovery started");
        }

        @Override
        public void onDiscoveryStopped(String serviceType) {
            Log.d(TAG, "Discovery stopped");
        }

        @Override
        public void onServiceFound(NsdServiceInfo serviceInfo) {
            Log.d(TAG, "Service found: " + serviceInfo.getServiceName());
            if (serviceInfo.getServiceType().equals(serviceType)) {
                mNsdManager.resolveService(serviceInfo, mResolveListener);
            }
        }

        @Override
        public void onServiceLost(NsdServiceInfo serviceInfo) {
            Log.d(TAG, "Service lost: " + serviceInfo.getServiceName());
        }
    };
}
 
开发者ID:mannaz,项目名称:ahc,代码行数:37,代码来源:BonjourManager.java

示例2: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
private void initializeDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {
        @Override
        public void onDiscoveryStarted(String regType) {
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            String name = service.getServiceName();
            String type = service.getServiceType();
            Log.d(Constants.TAG, "Service Name=" + name);
            Log.d(Constants.TAG, "Service Type=" + type);
            if (type.equals(SERVICE_TYPE) && name.contains("rcontrol")) {
                Log.d(Constants.TAG, "Service Found @ '" + name + "'");
                mNsdManager.resolveService(service, mResolveListener);
            }
        }

        @Override
        public void onServiceLost(NsdServiceInfo service) {
        }

        @Override
        public void onDiscoveryStopped(String serviceType) {
        }

        @Override
        public void onStartDiscoveryFailed(String serviceType, int errorCode) {
            mNsdManager.stopServiceDiscovery(this);
        }

        @Override
        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            mNsdManager.stopServiceDiscovery(this);
        }
    };
}
 
开发者ID:andreldm,项目名称:rcontrol,代码行数:38,代码来源:ServiceFinder.java

示例3: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
private void initializeDiscoveryListener() {

        // Instantiate a new DiscoveryListener
        mDiscoveryListener = new NsdManager.DiscoveryListener() {

            //  Called as soon as service discovery begins.
            @Override
            public void onDiscoveryStarted(String regType) {
                Log.d(TAG, "Service discovery started");
            }

            @Override
            public void onServiceFound(NsdServiceInfo service) {
                // A service was found!  Do something with it.
                Log.d(TAG, "Service discovery success" + service);
                if (!service.getServiceType().equals(NSDSender.SERVICE_TYPE)) {
                    // Service type is the string containing the protocol and
                    // transport layer for this service.
                    //    Log.d(TAG, "Unknown Service Type: " + service.getServiceType());

                } else if (service.getServiceName().contains(NSDSender.SERVICE_NAME_DEFAULT)) {

                    mNsdManager.resolveService(service, new NsdManager.ResolveListener() {

                        @Override
                        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
                            // Called when the resolve fails.  Use the error code to debug.
                            Log.e(TAG, "Resolve failed" + errorCode);
                        }

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

                            int port = serviceInfo.getPort();
                            InetAddress host = serviceInfo.getHost();

                            Neighbor neighbor = new Neighbor(host.getHostAddress(),host.getHostName(),Neighbor.TYPE_WIFI_NSD);
                            if (mNearbyListener != null)
                                mNearbyListener.foundNeighbor(neighbor);

                            connect(host, port);
                        }
                    });
                }
            }

            @Override
            public void onServiceLost(NsdServiceInfo service) {
                // When the network service is no longer available.
                // Internal bookkeeping code goes here.
                Log.e(TAG, "service lost" + service);
            }

            @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);
                mNsdManager.stopServiceDiscovery(this);
            }

            @Override
            public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                mNsdManager.stopServiceDiscovery(this);
            }
        };
    }
 
开发者ID:n8fr8,项目名称:LittleBitLouder,代码行数:73,代码来源:NSDReceiver.java

示例4: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {

        @Override
        public void onDiscoveryStarted(String regType) {
            Log.d(TAG, "Service discovery started");
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            Log.d(TAG, "Service discovery success" + service);
            if (!service.getServiceType().equals(SERVICE_TYPE)) {
                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)){
                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);
        }
    };
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:45,代码来源:NsdHelper.java

示例5: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {
        mDiscoveryListener = new NsdManager.DiscoveryListener() {
            @Override
            public void onDiscoveryStarted(String regType) {
                Log.d(TAG, "Service discovery started");
                callCallback(CallbackTypeEnum.DiscoveryStarted);
            }

            @Override
            public void onServiceFound(NsdServiceInfo service) {
                Log.d(TAG, "Service discovery success" + service);
                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
                if (!service.getServiceType().equals(SERVICE_TYPE)) {
                    Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
                } else if (service.getServiceName().equals(mServiceName)) {
                    Log.d(TAG, "Possibly Same machine: " + mServiceName);
                } else if (service.getServiceName().contains(mServiceName)) {
                    Log.d(TAG, "Possibly different machines. (" + service.getServiceName() + "-" +
                            mServiceName + ")");
                }
                servicesFound.add(service);
                callCallback(CallbackTypeEnum.ServiceFound);

/*                if (bResolve)
                    mNsdManager.resolveService(service, mResolveListener);*/
            }

            @Override
            public void onServiceLost(NsdServiceInfo service) {
                Log.e(TAG, "service lost" + service);
                if (mService == service) {
                    mService = null;
                }
                callCallback(CallbackTypeEnum.ServiceLost);
            }

            @Override
            public void onDiscoveryStopped(String serviceType) {
                Log.i(TAG, "Discovery stopped: " + serviceType);
                callCallback(CallbackTypeEnum.DiscoveryStopped);
            }

            @Override
            public void onStartDiscoveryFailed(String serviceType, int errorCode) {
                Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                mNsdManager.stopServiceDiscovery(this);
                callCallback(CallbackTypeEnum.StartDiscoveryFailed);
            }

            @Override
            public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                mNsdManager.stopServiceDiscovery(this);
                callCallback(CallbackTypeEnum.StopDiscoveryFailed);
            }
        };
    }
 
开发者ID:ekalyvio,项目名称:CowBit,代码行数:61,代码来源:NsdHelper.java

示例6: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
private void initializeDiscoveryListener() {

        if (mDiscoveryListener != null) {
            try {
                mNsdManager.stopServiceDiscovery(mDiscoveryListener);
                UserError.Log.wtf(TAG, "Discovery service was active when it shouldn't be!");
            } catch (Exception e) {
                UserError.Log.d(TAG, "Could not stop service during initialization: " + e);
            }
        }
        mDiscoveryListener = new NsdManager.DiscoveryListener() {


            @Override
            public void onDiscoveryStarted(String regType) {
            }

            @Override
            public synchronized void onServiceFound(final NsdServiceInfo service) {

                final String type = service.getServiceType();

                if (type.equals(SERVICE_TYPE)) {
                    final String name = service.getServiceName();
                    final LookUpInfo li = iplookup.get(shortenName(name));
                    if ((li == null) || (JoH.msSince(li.received) > CACHE_REFRESH_MS)) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                singleResolveService(service);
                            }
                        }).start();
                    } else {
                        UserError.Log.d(TAG, "Already have recent data for: " + name + " => " + li.address);
                    }
                }
            }


            @Override
            public void onServiceLost(NsdServiceInfo service) {
            }

            @Override
            public void onDiscoveryStopped(String serviceType) {
            }

            @Override
            public void onStartDiscoveryFailed(String serviceType, int errorCode) {
                myStopServiceDiscovery();
            }

            @Override
            public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                if (JoH.ratelimit("mdns-onStopDiscoveryFailed", 10)) {
                    myStopServiceDiscovery();
                }
            }

            private void myStopServiceDiscovery() {
                try {
                    mNsdManager.stopServiceDiscovery(this);
                } catch (IllegalArgumentException | IllegalStateException e) {
                    UserError.Log.e(TAG, "Could not stop service discovery: " + e);
                }
            }
        };
    }
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:69,代码来源:Mdns.java

示例7: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {

        @Override
        public void onDiscoveryStarted(String regType) {
            Log.d(TAG, "Service discovery started");
            Toast.makeText(mContext, "Discovery started", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            Log.d(TAG, "Service discovery success" + service);
            Toast.makeText(mContext, "Service discovery success" + service, Toast.LENGTH_SHORT).show();
            if (!service.getServiceType().equals(SERVICE_TYPE)) {
                Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
                Toast.makeText(mContext, "Unknown Service Type: " + service.getServiceType(), Toast.LENGTH_SHORT).show();
            } else if ((service.getServiceName().equals(mServiceName)) && flag) {
                Log.d(TAG, "Same machine: " + mServiceName);
                Toast.makeText(mContext, "Same machine: " + mServiceName, Toast.LENGTH_SHORT).show();
            } else if (service.getServiceName().equals(mServiceName)) {
                Log.e(TAG,"resolving");
                mNsdManager.resolveService(service, mResolveListener);
            }
        }

        @Override
        public void onServiceLost(NsdServiceInfo service) {
            Log.e(TAG, "Service lost: " + service);
            Toast.makeText(mContext, "Service lost: " + service, Toast.LENGTH_SHORT).show();
            if (mService == service) {
                mService = null;
            }
        }

        @Override
        public void onDiscoveryStopped(String serviceType) {
            Log.i(TAG, "Discovery stopped: " + serviceType);
            Toast.makeText(mContext, "Discovery stopped: " + serviceType, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onStartDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            Toast.makeText(mContext, "Discovery start failed: Error code:" + errorCode, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            Toast.makeText(mContext, "Discovery stop failed: Error code:" + errorCode, Toast.LENGTH_SHORT).show();
        }
    };
}
 
开发者ID:suchoX,项目名称:Simplify,代码行数:54,代码来源:NsdHelper.java

示例8: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {
        @Override
        public void onDiscoveryStarted(String regType) {
            Log.d(TAG, "Service discovery started");
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            Log.d(TAG, "Service discovery success" + service);
            if (!service.getServiceType().equals(SERVICE_TYPE)) {
                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)) {
                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);
        }
    };
}
 
开发者ID:MycroftAI,项目名称:Mycroft-Android,代码行数:44,代码来源:NetworkAutoDiscoveryUtil.java

示例9: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {

        // Instantiate a new DiscoveryListener
        mDiscoveryListener = new NsdManager.DiscoveryListener() {

            //  Called as soon as service discovery begins.
            @Override
            public void onDiscoveryStarted(String regType) {
                Log.d(TAG, "Service discovery started");
            }

            @Override
            public void onServiceFound(NsdServiceInfo service) {
                // A service was found!  Do something with it.
                Log.d(TAG, "Service discovery success: " + service);
                if (!service.getServiceType().equals(SERVICE_TYPE)) {
                    // Service type is the string containing the protocol and
                    // transport layer for this service.
                    Log.d(TAG, "Mycroft found!: " + service.getServiceType() + "  " + service.getHost() + "  " + service.getPort());
                    resolveService(service);
                }
            }

            @Override
            public void onServiceLost(NsdServiceInfo service) {
                // When the network service is no longer available.
                // Internal bookkeeping code goes here.
                Log.e(TAG, "service lost: " + service);
            }

            @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);
                mNsdManager.stopServiceDiscovery(this);
            }

            @Override
            public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                Log.e(TAG, "Discovery failed: Error code: " + errorCode);
                mNsdManager.stopServiceDiscovery(this);
            }
        };
    }
 
开发者ID:MycroftAI,项目名称:Mycroft-Android,代码行数:49,代码来源:DiscoveryActivity.java

示例10: discoverServices

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
protected void discoverServices(String serviceType, int protocol, NsdManager.DiscoveryListener listener) {
    ((NsdManager) mContext.getSystemService(Context.NSD_SERVICE)).discoverServices(serviceType, protocol, listener);
}
 
开发者ID:youviewtv,项目名称:tinydnssd,代码行数:4,代码来源:DiscoverResolver.java

示例11: stopServiceDiscovery

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
protected void stopServiceDiscovery(NsdManager.DiscoveryListener listener) {
    ((NsdManager) mContext.getSystemService(Context.NSD_SERVICE)).stopServiceDiscovery(listener);
}
 
开发者ID:youviewtv,项目名称:tinydnssd,代码行数:4,代码来源:DiscoverResolver.java

示例12: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {
        public void onDiscoveryStarted(String regType) {
            Log.d(TAG, "Service discovery started");
            setDiscovering(true);
        }

        public void onServiceFound(NsdServiceInfo service) {
            Log.d(TAG, "Service discovery success" + service);
            if (!service.getServiceType().equals(SERVICE_TYPE)) {
                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)){
                Toast.makeText(mContext, "Service "+service.getServiceName()+" found!!!",Toast.LENGTH_SHORT).show();
                Log.d(TAG, "Service: " + service.getServiceName() + " found!!!");
                mNsdManager.resolveService(service, mResolveListener);
            }
        }

        public void onServiceLost(NsdServiceInfo service) {
            Log.e(TAG, "service lost" + service);
            Toast.makeText(mContext, "Service lost",Toast.LENGTH_SHORT).show();
            if (mService == service) {
                mService = null;
            }
        }
        
        public void onDiscoveryStopped(String serviceType) {
            Log.i(TAG, "Discovery stopped: " + serviceType);
            setDiscovering(false);
        }

        public void onStartDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
        }

        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
        }
    };
}
 
开发者ID:ArianJM,项目名称:you2peer,代码行数:45,代码来源:NsdHelper.java

示例13: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
public void initializeDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {

        @Override
        public void onDiscoveryStarted(String regType) {
            Log.d(TAG, "Service discovery started");
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            Log.d(TAG, "Service discovery success" + service);
            try {
                mNsdManager.resolveService(service, mResolveListener);
            }
            catch (Exception e){
                Log.e(TAG, e.getMessage().toString());
            }/*
            if (!service.getServiceType().equals(SERVICE_TYPE)) {
                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)){
                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);
            mNsdManager.stopServiceDiscovery(this);
        }

        @Override
        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
        }
    };
}
 
开发者ID:alseambusher,项目名称:QuickFoods-android,代码行数:53,代码来源:NsdHelper.java

示例14: initDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
private void initDiscoveryListener() {
    mDiscoveryListener = new NsdManager.DiscoveryListener() {

        @Override
        public void onDiscoveryStarted(String regType) {
            Timber.d("Service discovery started");
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            Timber.d("Service discovery success" + service);

            try {
                mNsdManager.resolveService(service, mResolveListener);
            } catch (IllegalArgumentException ex) {
                ex.printStackTrace();
            }
        }

        @Override
        public void onServiceLost(NsdServiceInfo service) {
            Timber.e("service lost " + service);

            if(onNsdChangeListener != null) {
                onNsdChangeListener.onServiceLost(service);
            } else {
                Timber.e("no OnNsdChangeListener set");
            }
        }

        @Override
        public void onDiscoveryStopped(String serviceType) {
            Timber.i("Discovery stopped: " + serviceType);
        }

        @Override
        public void onStartDiscoveryFailed(String serviceType, int errorCode) {
            Timber.e("Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
        }

        @Override
        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            Timber.e("Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
        }
    };
}
 
开发者ID:bennir,项目名称:DVBViewerRemote,代码行数:49,代码来源:NsdService.java

示例15: initializeDiscoveryListener

import android.net.nsd.NsdManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void initializeDiscoveryListener() {

    // Instantiate a new DiscoveryListener
    mDiscoveryListener = new NsdManager.DiscoveryListener() {

        //  Called as soon as service discovery begins.
        @Override
        public void onDiscoveryStarted(String regType) {
            Log.d(TAG, "Service discovery started");
        }

        @Override
        public void onServiceFound(NsdServiceInfo service) {
            // A service was found!  Do something with it.
            Log.d(TAG, "Service discovery success" + service);
            if (!service.getServiceType().equals(SERVICE_TYPE)) {
                // Service type is the string containing the protocol and
                // transport layer for this service.
                Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
            } else if (service.getServiceName().equals(SERVICE_NAME)) {
                Log.d(TAG, "Found CommCare Micronode");

                mNsdManager.resolveService(service, getResolveListener());
            }
        }

        @Override
        public void onServiceLost(NsdServiceInfo service) {
            // When the network service is no longer available.
            // Internal bookkeeping code goes here.
            Log.e(TAG, "service lost" + service);
        }

        @Override
        public void onDiscoveryStopped(String serviceType) {
            Log.i(TAG, "Discovery stopped: " + serviceType);
            state = NsdState.Idle;
        }

        @Override
        public void onStartDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
            state = NsdState.Idle;
        }

        @Override
        public void onStopDiscoveryFailed(String serviceType, int errorCode) {
            Log.e(TAG, "Discovery failed: Error code:" + errorCode);
            mNsdManager.stopServiceDiscovery(this);
        }
    };
}
 
开发者ID:dimagi,项目名称:commcare-android,代码行数:55,代码来源:NSDDiscoveryTools.java


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