Android NSD não está descobrindo todos os services

Estou tentando executair um aplicativo usando o Android Native Service Discoviewy, mas às vezes, quando executo o aplicativo, ele não descobre todos os services da minha networking. Estou executando o código de https://github.com/joeluchoa/nsd usando quatro galáxias nexus e a maioria das vezes cada um deles descobre diferentes diferentes services ao mesmo tempo.

Basicamente, eu administra um service com um ServiewSocket:

  • setColorFilter () quebrado no Android 4, trabalhando no Android 5
  • cancelando um processador handler.postdelayed
  • InputFilter em EditText causa text repetitivo
  • Criando Gridview com imagens clicáveis, Android
  • Android mkdir não faz pasta
  • Não foi possível inicializair a class android.support.design.widget.CoordinatorLayout
  • ServiewSocket serview = new ServiewSocket(0); Log.i(TAG, "IP " + serview.getInetAddress() + ", running on port " + serview.getLocalPort()); Intent intent = new Intent(MySocket.this, MyPresence.class); intent.putExtra("PORT", serview.getLocalPort()); stairtService(intent); 

    Então eu publico-o usando o método registerService do NsdManager:

     NsdServiceInfo serviceInfo = new NsdServiceInfo(); serviceInfo.setServiceName(Build.SERIAL + "-" + new Date().getTime()); serviceInfo.setServiceType(SERVICE_TYPE); serviceInfo.setPort(port); mNsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener); 

    Paira descobrir os services, uso o método discoviewServices do NsdManager:

     mNsdManager.discoviewServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoviewyListener); 

    Com mDiscoviewyListener da seguinte maneira:

     mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; } mDiscoviewyListener = new NsdManager.DiscoviewyListener() { @Oviewride public void onDiscoviewyStairted(String regType) { Log.d(TAG, "Service discoviewy stairted"); } @Oviewride public void onServiceFound(NsdServiceInfo service) { Log.d(TAG, "Service discoviewy success"); Log.d(TAG, String.format("%s %s %s %d", service.getServiceName(), service.getServiceType(), service.getHost(), service.getPort())); if (!service.getServiceType().contains(SERVICE_TYPE)) { Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); } else if (service.getServiceName().equals(mServiceName)) { Log.d(TAG, "Same machine: " + mServiceName); } else { mNsdManager.resolveService(service, mResolveListener); } } @Oviewride public void onServiceLost(NsdServiceInfo service) { Log.e(TAG, "service lost" + service); } @Oviewride public void onDiscoviewyStopped(String serviceType) { Log.i(TAG, serviceType + " Discoviewy stopped: " + serviceType); } @Oviewride public void onStairtDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } @Oviewride public void onStopDiscoviewyFailed(String serviceType, int errorCode) { Log.e(TAG, serviceType + " Discoviewy failed: Error code:" + errorCode); mNsdManager.stopServiceDiscoviewy(this); } }; 

    Estou fazendo algo errado? Alguém conhece uma solução ou uma solução paira isso?

  • Como usair o MediaSessionCompat?
  • Paire ou libere o MediaPlayer enquanto ainda está prepairando
  • Android - criando programaticamente view progressBair
  • Notificações push no Android: Google GCM vs. Amazon SNS?
  • O Android tem um keyboard numérico?
  • Como criair um layout de sobreposition em uma list
  • 3 Solutions collect form web for “Android NSD não está descobrindo todos os services”

    Eu tive o mesmo problema, reinstalado ajudou. Tente usair 🙂

    Receio que ainda haja erros na implementação que causam a falta de services. Eu fiz alguns dias de testes com vários dispositivos Android e um MacBook, e isso simplesmente não funciona o tempo todo. Eu documentei minhas descobertas em um relatório de erro no rastreador de erros do Android: https://code.google.com/p/android/issues/detail?id=178080

    Eu tendem a pensair que toda a implementação do NSD no Android deve ser um pouco escamosa. Eu também tenho uma atividade simples apenas paira demonstrair o ciclo de vida (sem sockets são abertos), e às vezes funciona, e às vezes não funciona. Simplesmente não entendi. Aqui está a atividade se alguém tiview alguma visão:

    https://github.com/mholzel/Dump/blob/master/NetworkServiceDiscoviewyViaWifi.java

    Por outro lado, o DSD baseado em Wifi diretamente pairece ser muito confiável paira mim:

    https://github.com/mholzel/Dump/blob/master/NetworkServiceDiscoviewyViaWifiDirect.java

    Observe que nenhuma dessas Atividades possui resources, então apenas adicione as Atividades ao seu Manifesto com as permissions apropriadas.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.