Using Android's WifiManager to scan for available Wifi networks is easy.
- Get a handle to WifiManager via
context.getSystemService
- Create an intent
- Create a broadcast receiver
- Register that receiver with the above intent
- Wait
- Loop through the scan results
What I had not realized was that this process once started just keeps rolling. As far as I can tell the only way to stop it is to unregister the broadcast receiver in question.
- Is this the only, and correct, way to stop scanning for wifi networks?
- If so is there really no need to issue something like WifiManager.stopScan (which does not appear to exist anyway)?
I am assuming that the device keeps scanning for wifi networks by default anyway so at a later time I can use the same WifiManger handle to grab a fresh list of available networks.
As you well assumed, the OS is tracking WiFi events anyway, by using WiFiManager you are just subscribing your application to receive certain types of notifications.
If your application is no longer interested in them, you should unregister your application receiver, avoiding unnecessary context switches on WiFi events.
The reference for WifiManager is not very descriptive, but you can find some hints about what the OS does in the ConenctivtyManager reference: https://developer.android.com/reference/android/net/ConnectivityManager.html