2

Android Network Service Discovery为我们提供了一个onResolveFailed()回调,如下所示:

NsdManager.ResolveListener mResolveListener = 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);
    }
};

就我而言,我得到错误代码 3。

这些 erorCodes 代表什么,我在哪里可以找到指定的?

4

2 回答 2

7

它就在您链接到的文档中

在此处输入图像描述

于 2015-05-04T09:44:09.853 回答
1

使用线程睡眠然后我们不能得到这种类型的错误

            @Override
    public void onServiceFound(final NsdServiceInfo service) {

       if(service.getServiceName()!=null) {


              try {

            Log.d(TAG, "Service discovery success = " + service.toString());

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


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


                          String mHostFound = serviceInfo.getHost().getHostAddress();
                          int mPortFound = serviceInfo.getPort();


                          System.out.println(serviceInfo.getServiceName());
                          System.out.println(mHostFound);
                          System.out.println(mPortFound);

                      }
                  });


              } catch (Exception e) {
                  e.printStackTrace();
              }

            }


    }                

这对我有用,谢谢

于 2020-01-04T09:30:50.613 回答