问题描述
我想了解为什么在从静态方法调用 Nsdmanager 时会出现此问题,代码如下
public void initializediscoveryListener() {
// Instantiate a new discoveryListener
discoveryListener = 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(serviceName)) {
// The name of the service tells the user what they'd be
// connecting to. It Could be "Bob's Chat App".
Log.d(TAG,"Same machine: " + serviceName);
} else if (service.getServiceName().contains("NsdChat")){
// nsdManager.resolveService(service,resolveListener);
}
}
@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);
nsdManager.stopServicediscovery(this);
}
@Override
public void onStopdiscoveryFailed(String serviceType,"discovery Failed: Error code:" + errorCode);
nsdManager.stopServicediscovery(this);
}
};
}
public static void discover(){
System.out.println("discoverServices");
nsdManager.discoverServices("_http._tcp.",NsdManager.PROTOCOL_DNS_SD,discoveryListener);
}
//nsdManager = (NsdManager)c.getSystemService(Context.NSD_SERVICE);
}
我遇到了以下问题:
** :\ProgQt\build-app-Android_for_armeabi_v7a_arm64_v8a_x86_x86_64_Clang_Qt_5_15_0_for_android-debug\android-build\src\org\qtproject\example\musiclist\MusicList.java:188 来自发现的非静态引用变量:错误不能是静态监听器:错误: context nsdManager.discoverServices("_http._tcp.",discoveryListener);**
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)