Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /** * This checks the system-side for network connectivity, then pings the google * server to make sure they have internet connection. One other method avail here for use * in checking via ConnectivityManager. * @param context Context to be passed * @return Returns a boolean, true if they have internet, false if they do not. */ public static boolean haveNetworkConnection3(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); } }