本文整理汇总了Java中android.net.nsd.NsdManager类的典型用法代码示例。如果您正苦于以下问题:Java NsdManager类的具体用法?Java NsdManager怎么用?Java NsdManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NsdManager类属于android.net.nsd包,在下文中一共展示了NsdManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerService
import android.net.nsd.NsdManager; //导入依赖的package包/类
private int registerService(Context context) throws java.io.IOException {
int port = findOpenSocket();
// Create the NsdServiceInfo object, and populate it.
NsdServiceInfo serviceInfo = new NsdServiceInfo();
// The name is subject to change based on conflicts
// with other services advertised on the same network.
serviceInfo.setServiceName(SERVICE_NAME_DEFAULT);
serviceInfo.setServiceType(SERVICE_TYPE);
serviceInfo.setPort(port);
mNsdManager = (NsdManager)context.getSystemService(Context.NSD_SERVICE);
if (mRegistrationListener == null)
initializeRegistrationListener();
mNsdManager.registerService(
serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);
return port;
}
示例2: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.e(TAG, "Resolve failed" + errorCode);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
if (serviceInfo.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
}
};
}
示例3: initializeRegistrationListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeRegistrationListener() {
mRegistrationListener = new NsdManager.RegistrationListener() {
@Override
public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
mServiceName = NsdServiceInfo.getServiceName();
Log.d(TAG, "Service registered: " + mServiceName);
}
@Override
public void onRegistrationFailed(NsdServiceInfo arg0, int arg1) {
Log.d(TAG, "Service registration failed: " + arg1);
}
@Override
public void onServiceUnregistered(NsdServiceInfo arg0) {
Log.d(TAG, "Service unregistered: " + arg0.getServiceName());
}
@Override
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.d(TAG, "Service unregistration failed: " + errorCode);
}
};
}
示例4: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.e(TAG, "Resolve failed " + errorCode);
mService = null;
callCallback(CallbackTypeEnum.ResolveFailed);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.v(TAG, "Resolve Succeeded. " + serviceInfo);
if (serviceInfo.getServiceName().equals(mServiceName)) {
// Log.d(TAG, "Same IP.");
// return;
}
mService = serviceInfo;
callCallback(CallbackTypeEnum.ServiceResolved);
}
};
}
示例5: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.e(TAG, "Resolve failed" + errorCode);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
if (serviceInfo.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
}
};
}
示例6: initializeRegistrationListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeRegistrationListener() {
mRegistrationListener = new NsdManager.RegistrationListener() {
@Override
public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
mServiceName = NsdServiceInfo.getServiceName();
Log.d(TAG, "Service registered: " + mServiceName);
}
@Override
public void onRegistrationFailed(NsdServiceInfo arg0, int arg1) {
Log.d(TAG, "Service registration failed: " + arg1);
}
@Override
public void onServiceUnregistered(NsdServiceInfo arg0) {
Log.d(TAG, "Service unregistered: " + arg0.getServiceName());
}
@Override
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.d(TAG, "Service unregistration failed: " + errorCode);
}
};
}
示例7: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
private void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.d(TAG, "Resolve failed");
}
@Override
public void onServiceResolved(final NsdServiceInfo serviceInfo) {
Log.d(TAG, "Service resolved :" + serviceInfo);
final String hostName = serviceInfo.getHost().getHostName();
final int port = serviceInfo.getPort();
final String serviceName = serviceInfo.getServiceName();
handler.post(new Runnable() {
@Override
public void run() {
serviceDiscoveryListener.onBonjourServiceDiscovered(hostName, port, serviceName);
}
});
}
};
}
示例8: registerService
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void registerService(final int port, final String serviceName, final String serviceType, final Map<String, String> attributes, final EventCallback callback) {
Log.d(LOGTAG, "registerService: " + serviceName + "." + serviceType + ":" + port);
synchronized (this) {
if (mStartCallback != null) {
throw new RuntimeException("Previous operation is not finished");
}
mStartCallback = callback;
}
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setPort(port);
serviceInfo.setServiceName(serviceName);
serviceInfo.setServiceType(serviceType);
setAttributes(serviceInfo, attributes);
nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, this);
}
示例9: onCreate
import android.net.nsd.NsdManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send_message);
try
{
nsdManager = (NsdManager) this.getSystemService(NSD_SERVICE);
nsdHelper = new NSDHelper(nsdManager);
nsdHelper.clientThreadInitComplete = this;
nsdHelper.discoverNetworkServices(SERVICE_TYPE);
}
catch (IOException | IllegalArgumentException e)
{
e.printStackTrace();
}
}
示例10: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
private void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.e(Constants.TAG, "Resolve failed" + errorCode);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
mServiceInfo = serviceInfo;
int port = mServiceInfo.getPort();
InetAddress host = mServiceInfo.getHost();
String address = host.getHostAddress();
Log.d(Constants.TAG, "Resolved address = " + address);
ServerInfo service = new ServerInfo(address, port);
mServers.add(service);
}
};
}
示例11: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Toast.makeText(mContext, "Resolve failed",Toast.LENGTH_SHORT).show();
Log.e(TAG, "Resolve failed" + errorCode);
}
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.d(TAG, "Resolve Succeeded. " + serviceInfo);
Toast.makeText(mContext, "Resolve succeeded",Toast.LENGTH_SHORT).show();
if (serviceInfo.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
setConnected(true);
}
};
}
示例12: onCreate
import android.net.nsd.NsdManager; //导入依赖的package包/类
@Override
public void onCreate() {
httpService = this;
Log.d(TAG, "My Service Created");
try {
server = new NanoHTTPDReceiver( //
0, //
new File("/"), //
getApplicationContext() //
);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(TAG, "using port " + server.getLocalPort());
NsdServiceInfo nsi = new NsdServiceInfo();
nsi.setPort(server.getLocalPort());
nsi.setServiceName("MultiShare");
nsi.setServiceType("_http._tcp.");
mNsdManager = (NsdManager) getSystemService(Context.NSD_SERVICE);
mNsdManager.registerService(nsi, NsdManager.PROTOCOL_DNS_SD, this);
}
示例13: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeResolveListener()
{
mResolveListener = new NsdManager.ResolveListener()
{
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode)
{
Log.e(TAG, "Resolve failed" + errorCode);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo)
{
Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
if (serviceInfo.getServiceName().equals(mServiceName))
{
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
}
};
}
示例14: initializeResolveListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.e(TAG, "Resolve failed" + errorCode);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
mService = serviceInfo;
/*
if (serviceInfo.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
*/
}
};
}
示例15: initializeRegistrationListener
import android.net.nsd.NsdManager; //导入依赖的package包/类
public void initializeRegistrationListener() {
mRegistrationListener = new NsdManager.RegistrationListener() {
@Override
public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
mServiceName = NsdServiceInfo.getServiceName();
}
@Override
public void onRegistrationFailed(NsdServiceInfo arg0, int arg1) {
}
@Override
public void onServiceUnregistered(NsdServiceInfo arg0) {
}
@Override
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
}
};
}