Here you can find the source of haveNetworkConnection(Context context)
private static boolean haveNetworkConnection(Context context)
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { private static boolean haveNetworkConnection(Context context) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }/*from ww w . j a va 2 s. c om*/ return haveConnectedWifi || haveConnectedMobile; } }