How to check if wifi is connected in android

If you want to try downloading something unless you have wifi. You can use the following code snippet to be able to check if wifi is enabled.

You will be able to use the ConnectivityManager to get the state of the Wifi adapter. From there you canĀ check if it is connected or even available.

ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if (mWifi.isConnected()) {
    // Do whatever
}

Note: Add


to your AndroidManifest.xml for this to work.