Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /** * Method to check if network is available. * * @param context the context * @return Flag indicating if Network is available or not */ public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); } }