Here you can find the source of hasInternetConnection(Context context)
public static boolean hasInternetConnection(Context context)
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static boolean hasInternetConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnectedOrConnecting(); }/*from w w w . j a va 2 s. c om*/ }