Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; public class Main { /** * Check to see if the network is available. * @return true if there is access to the internet, false otherwise. */ public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); boolean isAvailable = false; if (info != null && info.isConnected()) { isAvailable = true; } Log.v("TheNetUtil", "isNetworkAvailable(). net is " + isAvailable); return isAvailable; } }