Android NSD onResolveFailed() 的错误代码意味着什么
What do the errorCodes mean for Android NSD onResolveFailed()
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。
这些错误代码代表什么,我在哪里可以找到指定的代码?
它就在您 link 到
的文档中
使用线程休眠就不会出现这种类型的错误
@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();
}
}
}
这对我有用谢谢你
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。
这些错误代码代表什么,我在哪里可以找到指定的代码?
它就在您 link 到
的文档中使用线程休眠就不会出现这种类型的错误
@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();
}
}
}
这对我有用谢谢你