I need to know how I can detect a switch in Wi-Fi networks, albeit automatically or manually, it doesn’t matter. Is there some kind of intent being broadcasted throughout the system when a switch is detected? Or do I have to manually check if a new network is selected by calling a method on a ConnectivityManager?
Share
At this point in time, I have fixed this like this (haven’t fully tested it yet as I don’t have a second network available at the moment):
I extended the BroadcastReceiver class
I register this class as a receiver with a filter set to the
ConnectivityManager.CONNECTIVITY_ACTIONintent (setting it inonResume()and releasing it inonPause()). This ought to catch any automatic Wi-Fi network switch. ThegetOwnIpAddressretrieves the device’s IP address from theWifiManager.I’ve also found that it works when I return to the activity from another activity.