问题
I am quite new in the Android development. I have an app that tries to connect to other devices running android via Wi-Fi peer 2 peer. What I want to do is to see only the devices that have the same app installed rather than see all the available peers. Thanks in advance.
回答1:
Yeah you can do this!! :)
Try using the Wifi P2p for Service Discovery. Actually, the link is a training which teaches exactly what you want.
So, what you basically want to do is create a WifiP2pDnsSdServiceInfo
object that contains the information you want to advertise or the information that your app broadcasts and then, addLocalService
which advertises/broadcasts this object.
You also need to discover nearby services which are broadcasting some information. To get the service information, create a WifiP2pManager.DnsSdServiceResponseListener
. This receives the actual description and connection information. Here, you can read the information and if it is the information your app broadcasts, then Hooray you found a nearby device that has your particular application.
Tip: You can broadcast some application specific code like "This_is_my_App" and then some device specific information lets say Wifi MAC Address/DeviceName which helps you differentiate between different devices which you can populate in a List and display.
来源:https://stackoverflow.com/questions/33869983/how-to-find-devices-via-wi-fi-peer-2-peer-that-have-the-same-app-installed