8

I'm trying to implement a simple android application that broadcasts a WifiP2p bonjour service on one device and have a second device discover and connect to it. I've pretty much followed the tutorial here.

I have a valid Channel object, a DnsSdServiceResponseListener, and a DnsSdTxtRecordListener, and set them via this call:

mManager.setDnsSdResponseListeners(channel, servListener, txtListener);

As of right now both listeners just spit out some debugging info to keep it real simple.

The problem is that my DnsSdServiceResponseListener is never called, but the DnsSdTxtRecordListener does get called and all the arguments passed in look legit. How can one be called but not the other?

I am testing using two actual devices, both running android 4.2.2.

Thanks!

Greg Neiheisel
  • 590
  • 4
  • 12

1 Answers1

12

Finally figured it out.. kind of. When getting an instance of a service request, I was specifying the service instance name and type to match the values used when creating the service...

Registering the service: mServiceInfo = WifiP2pDnsSdServiceInfo.newInstance(Consts.SERVICE_INSTANCE, Consts.SERVICE_REG_TYPE, record);

Creating the service request: mServiceRequest = WifiP2pDnsSdServiceRequest.newInstance(Consts.SERVICE_INSTANCE, Consts.SERVICE_REG_TYPE);

I removed the arguments to the newInstance method when getting the service request... mServiceRequest = WifiP2pDnsSdServiceRequest.newInstance();

and both listeners are being called now. It seems like my first method would filter out other services being broadcasted nearby, which is why I originally opted for that overload.

Greg Neiheisel
  • 590
  • 4
  • 12