How to find devices via Wi-fi peer 2 peer, that have the same app installed?

倖福魔咒の 提交于 2019-12-23 04:24:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!