Here you can find the source of isNetAvailable(Context context)
public static Boolean isNetAvailable(Context context)
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static Boolean isNetAvailable(Context context) { try {/*from www .j a v a 2 s . com*/ ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = connectivityManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = connectivityManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo.isConnected() || mobileInfo.isConnected()) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; } }