如何通过Wi-Fi Peer 2 Peer查找安装了相同应用程序的设备? [英] How to find devices via Wi-fi peer 2 peer, that have the same app installed?
问题描述
我在Android开发中是一个新手.我有一个应用尝试通过Wi-Fi对等2对等连接到运行android的其他设备.我要做的是仅查看安装了相同应用程序的设备,而不是查看所有可用的对等设备.预先感谢.
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.
推荐答案
是的,您可以这样做! :)
Yeah you can do this!! :)
尝试使用 Wifi P2p进行服务发现一个>.实际上,该链接是一种培训,可以准确教授您想要的内容.
Try using the Wifi P2p for Service Discovery. Actually, the link is a training which teaches exactly what you want.
因此,您基本上想要做的是创建一个WifiP2pDnsSdServiceInfo
对象,该对象包含要发布的信息或应用程序广播的信息,然后创建addLocalService
进行广告/广播的对象.
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.
您还需要发现附近正在广播一些信息的服务.要获取服务信息,请创建WifiP2pManager.DnsSdServiceResponseListener
.这将接收实际的描述和连接信息.在这里,您可以阅读信息,如果它是您的应用程序广播的信息,那么 Hooray 您发现附近有一个具有您特定应用程序的设备.
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.
提示:您可以广播一些特定于应用程序的代码,例如"This_is_my_App",然后某些特定于设备的信息可以说出 Wifi MAC地址/设备名称,这可以帮助您区分不同的设备您可以将其填充在列表中并显示.
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.
这篇关于如何通过Wi-Fi Peer 2 Peer查找安装了相同应用程序的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!