Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; public class Main { /** Returns true if device is connected to Internet, otherwise false. */ public static boolean hasInternetConnection(final Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) { return true; } else { return false; } } }