Is WiFi Connected : WiFi « Network « Android






Is WiFi Connected

 
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

class Main {
  public static boolean IsWiFiConnected(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
        .getApplicationContext().getSystemService(
            Context.CONNECTIVITY_SERVICE);

    if (connectivity != null) {
      NetworkInfo[] info = connectivity.getAllNetworkInfo();
      if (info != null) {
        for (int i = 0; i < info.length; i++) {
          if (info[i].getTypeName().equals("WIFI")
              && info[i].isConnected())
            return true;
        }
      }
    }

    return false;
  }
}

   
  








Related examples in the same category

1.Is Wifi service enabled by Context.WIFI_SERVICE
2.Airplane Mode and turn Wifi On
3.Get System Wifi Ip Address
4.Allow WiFi or allow mobile