Android - 当检测到新的接入点时收到通知吗?
Android 是否提供位于新 Wifi 网络附近的通知?设备是否配置为连接到该 wifi 网络取决于设备是否为该特定 wifi 网络设置了 wifi 配置,但是是否可以在进入任何新的 wifi 网络时收到通知?
我看到了 WifiManager 类,但类内的状态似乎没有实现我想要做的事情。有什么想法吗?
Does Android provide a notification of being in vicinity of a new Wifi Network? Whether the device is configured to connect to that wifi network depends on whether the device has the wifi configuration set for that particular wifi network, but is it possible to get notification whenever entering any new wifi network?
I saw the WifiManager class but the states inside the class do not seem to achieve what I am trying to do. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用已注册的
BroadcastReceiver
来接收带有操作的意图:WifiManager.NETWORK_STATE_CHANGED_ACTION
。在此 BroadcastReceiver 中,您可以从 Intent 中提取 NetworkInfo 对象
:处理
ni.getState()
来检查wifi网络的连接/断开。这是您要找的吗?
回答后编辑
因此,如果您想知道哪些 wifi 网络可用,请使用 WifiManager.getScanResults() 这将为您提供
Scanresult
对象中的附近接入点列表。它们包含接入点的 SSID 和 BSSID,分别是它们的网络名称和 MAC 地址。您可以使用注册为通过操作
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION
接收意图的BroadcastReceiver
来异步获取此信息。然后系统每次执行wifi扫描时都会通知您,您可以检查自上次扫描以来是否出现了新的SSID(即网络名称)。最后,如果您希望比系统默认情况下更频繁地扫描,您可以使用
WifiManager.startScan()
自行触发 wifi 扫描。Use a
BroadcastReceiver
registered to receive intents with action:WifiManager.NETWORK_STATE_CHANGED_ACTION
.In this BroadcastReceiver, you can extract a NetworkInfo object from the intent:
Then process
ni.getState()
to check connections/disconnections from wifi networks.Is this what you were looking for?
Edit after answer
So if you want to know which wifi networks are available, use WifiManager.getScanResults() This gives you the list of nearby access points in
Scanresult
objects. Those contain the SSID and BSSID of the access points, which are respectively their network name and mac address.You can get this information asynchronously by using a
BroadcastReceiver
registered to receive intents with actionWifiManager.SCAN_RESULTS_AVAILABLE_ACTION
. Then you will be notified each time the system performs a wifi scan, and you can check if a new SSID (i.e. network name) has appeared since the last scan.And finally if you wish to scan more often than the system does by default, you can trigger wifi scans yourself using
WifiManager.startScan()
.