Android - 当检测到新的接入点时收到通知吗?

发布于 2024-10-04 02:14:35 字数 164 浏览 10 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的軌跡 2024-10-11 02:14:35

使用已注册的 BroadcastReceiver 来接收带有操作的意图:WifiManager.NETWORK_STATE_CHANGED_ACTION

在此 BroadcastReceiver 中,您可以从 Intent 中提取 NetworkInfo 对象

NetworkInfo ni = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);

:处理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:

NetworkInfo ni = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);

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 action WifiManager.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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文