What is a way to listen and receive an event when Wifi is enabled or disabled on Android?
Note that I am not looking for connectivity to the internet. I am just looking for an event which says wifi in the wifi settings was enabled.
What is a way to listen and receive an event when Wifi is enabled or disabled on Android?
Note that I am not looking for connectivity to the internet. I am just looking for an event which says wifi in the wifi settings was enabled.
Use WIFI_STATE_CHANGED_ACTION broadcast intent action to check Wi-Fi state.
Add this to your manifest file:
<receiver
android:name=".WifiReceiver" >
<intent-filter>
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
And use this class for receiving broadcast:
public class WifiReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Check the state here
int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1);
}
}