本文整理汇总了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());
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
}
};
}
示例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();
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
示例11: stopServiceDiscovery
import android.net.nsd.NsdManager; //导入方法依赖的package包/类
protected void stopServiceDiscovery(NsdManager.DiscoveryListener listener) {
((NsdManager) mContext.getSystemService(Context.NSD_SERVICE)).stopServiceDiscovery(listener);
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}