Android - Get Notified when a new access point is detected?

China☆狼群 提交于 2019-12-06 01:24:41

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

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