Here you can find the source of IsNetworkConnected(Context context)
public static Boolean IsNetworkConnected(Context context)
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static Boolean IsNetworkConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] networks = manager.getAllNetworkInfo(); for (NetworkInfo network : networks) { if (network.getTypeName().equalsIgnoreCase("WIFI")) { if (network.isConnected() && network.isAvailable() && network.isConnectedOrConnecting()) { return true; }/*from w w w . j a va 2s. com*/ } if (network.getTypeName().equalsIgnoreCase("MOBILE")) { if (network.isConnected() && network.isAvailable() && network.isConnectedOrConnecting()) { return true; } } } return false; } }