I’m making an application for Android that needs to react to when the device gets connected to a WiFi network, I’m currently trying to implement it using a BroadcastReceiver to monitor android.net.ConnectivityManager.CONNECTIVITY_ACTION – is this way correct, or is there a way that would be more appropriate?
Share
@Jase, You need to register to receive
WifiManager.NETWORK_STATE_CHANGED_ACTION. The intent has aNetworkInfoextra. Examine it to find its state. If the state isNetworkInfo.State.CONNECTED, then you are connected to a network.For sample code on achieving this, look here.