Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.net.ConnectivityManager; import android.util.Log; public class Main { static String TAG = "Commons"; static boolean enableLogs = false; public static boolean isOnline(Context ctx) { try { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting(); } catch (Exception ex) { if (enableLogs) Log.e(TAG, ex.toString()); } return false; } }