Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Wifi Direct Service Discovery

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!

like image 424
Greg Neiheisel Avatar asked Mar 08 '13 03:03

Greg Neiheisel


People also ask

What is Wi-Fi Direct network discovery?

Wi-Fi Direct is similar in concept to “ad-hoc” Wi-Fi mode. However, unlike an ad-hoc Wi-Fi connection, Wi-Fi Direct includes an easier way to automatically discover nearby devices and connect to them.

What is Discovery Service Android?

Network service discovery (NSD) gives your app access to services that other devices provide on a local network. Devices that support NSD include printers, webcams, HTTPS servers, and other mobile devices.

How did Wi-Fi Direct get on my phone?

To check the status of Wi-Fi Direct on your device, go into Settings -> Network & internet -> Wi-Fi -> Wi-Fi preferences and then tap Wi-Fi Direct. Your smartphone will start scanning for devices that you can connect to. Unlike with Bluetooth, there is no button or anything that you need to tap to turn Wi-Fi Direct on.

What does Wi-Fi Direct do on Android?

Wi-Fi Direct (also known as peer-to-peer or P2P) allows your application to quickly find and interact with nearby devices, at a range beyond the capabilities of Bluetooth. The Wi-Fi Direct (P2P) APIs allow applications to connect to nearby devices without needing to connect to a network or hotspot.


1 Answers

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.

like image 148
Greg Neiheisel Avatar answered Sep 26 '22 02:09

Greg Neiheisel