Android Wifi Direct Service Discovery

I'm trying to implement a simple Android application that will transfer the Bonjour WifiP2p service on one device and open the second device and connect to it. I pretty much followed the tutorial here .

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

 mManager.setDnsSdResponseListeners(channel, servListener, txtListener); 

As of now, both listeners simply spit out some debugging information to keep it simple.

The problem is that my DnsSdServiceResponseListener never called, but the call to DnsSdTxtRecordListener calls the call, and all the arguments passed to the field look legal. How can you call, but not another?

I am testing using two real devices running Android 4.2.2.

Thanks!

+7
source share
1 answer

Finally realized this .. kind of. When I received an instance of a service request, I specified the name of the service instance and type so that they match the values ​​used when creating the service ...

Service registration: mServiceInfo = WifiP2pDnsSdServiceInfo.newInstance(Consts.SERVICE_INSTANCE, Consts.SERVICE_REG_TYPE, record);

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

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

and both listeners are being called now. It seems like my first method was filtering out other services that were broadcast nearby, so I initially chose this overload.

+10
source

All Articles