Android的 - 检测到新的接入点时,收到通知? [英] Android - Get Notified when a new access point is detected?

查看:156
本文介绍了Android的 - 检测到新的接入点时,收到通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确实的Andr​​oid提供了一个新的WLAN网络附近被通知?是否该设备被配置为连接到该无线网络取决于设备是否具有无线配置该特定无线网络设定,但是有可能得到通知,每当输入任何新的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?

推荐答案

使用广播接收器注册用行动收到意向: WifiManager.NETWORK_STATE_CHANGED_ACTION

Use a BroadcastReceiver registered to receive intents with action: WifiManager.NETWORK_STATE_CHANGED_ACTION.

在此广播接收器,您可以从意向提取的NetworkInfo 对象:

In this BroadcastReceiver, you can extract a NetworkInfo object from the intent:

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

然后再处理 ni.getState()从WiFi网络连接查看/断开。

Then process ni.getState() to check connections/disconnections from wifi networks.

这是你要找的是什么?

答案后,编辑

所以,如果你想知道哪些WiFi网络可用,使用<一个href=\"http://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults%28%29\">WifiManager.getScanResults()这给你附近接入点的 Scanresult 对象名单。那些包含的接入点,分别为他们的网络名称和MAC地址的SSID和BSSID。

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.

您可以使用广播接收器注册接收用行动意图 WifiManager.SCAN_RESULTS_AVAILABLE_ACTION 异步获取此信息。然后你会在系统每次执行一个WiFi扫描时间得到通​​知,你可以检查自上次扫描一个新的SSID(即网络名称)已经出现。

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.

最后,如果你想更多的往往比系统确实在默认情况下扫描,可以触发的wifi使用扫描自己 WifiManager.startScan()

And finally if you wish to scan more often than the system does by default, you can trigger wifi scans yourself using WifiManager.startScan().

这篇关于Android的 - 检测到新的接入点时,收到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆