i'm android developer in korea. I have some problem so I enter this site. I already search in web site, but I didn't solve a problem.
protected void onStart{
if(android.os.Build.VERSION.SDK_INT > 9){
StrictMode.ThreadPolicy.Builder builder = new Builder();
StrictMode.ThreadPolicy policy = builder.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
mMulticastLock = wifi.createMulticastLock("mDNSLock");
mMulticastLock.setReferenceCounted(true);
mMulticastLock.acquire();
String ip = Formatter.formatIpAddress(wifi.getConnectionInfo().getIpAddress());
mJmDNSManager = JmDNS.create(ip);
//mJmDNSManager.addServiceListener(TYPE, mJmDNSServiceListener);
mJmDNSManager.addServiceTypeListener(mJmDNSServiceTypeListener);
}
private ServiceTypeListener mJmDNSServiceTypeListener = new ServiceTypeListener() {
@Override
public void subTypeForServiceTypeAdded(ServiceEvent event) {
// TODO Auto-generated method stub
Log.v(TAG, "== subTypeForServiceTypeAdded: "+ event.getType());
}
@Override
public void serviceTypeAdded(ServiceEvent event) {
// TODO Auto-generated method stub
Log.v(TAG, "== serviceTypeAdded: " + event.getType());
mJmDNSManager.addServiceListener(event.getType(), mJmDNSServiceListener);
}
};
protected ServiceListener mJmDNSServiceListener = new ServiceListener(){
@Override
public void serviceAdded(ServiceEvent event) {
// TODO Auto-generated method stub
Looper.prepare();
Log.v(TAG, "== serviceAdded : " + event.getName());
mServiceEvents = new ArrayList<ServiceEvent>();
//mJmDNSManager.requestServiceInfo(event.getType(), event.getName(), 1);
ServiceInfo info = event.getInfo();
Toast.makeText(MainActivity.this, "onServiceAdded : " + info.getName() +
"/" + info.getType() + "/" + info.getPort(), Toast.LENGTH_LONG).show();
mServiceEvents.add(event);
Log.v(TAG, "==mServiceEvents.size() : " + mServiceEvents.size());
if(mServiceEvents.size() == 1) {
autoPairing();
}
else {
progressDialog.dismiss();
if (mDialog != null && !mDialog.isRemoving()) mDialog.dismiss();
mDialog = new SelectDeviceDialog();
mDialog.show(getFragmentManager(), "SelectDeviceDialog");
}
Looper.loop();
}
@Override
public void serviceRemoved(ServiceEvent event) {
// TODO Auto-generated method stub
Log.v(TAG, "== serviceRemoved: " + event.getName());
}
@Override
public void serviceResolved(ServiceEvent event) {
// TODO Auto-generated method stub
Log.v(TAG, "== serviceResolved: " + event.getInfo().getQualifiedName() + "
port:" + event.getInfo().getPort());
}
};
ServiceListener and ServiceTypeListener didn't work. so I want to know that solve the problem. thanks any reply.