Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /** * Checks if a network is currently enabled on the device * * @param ctx * @return */ public static boolean isNetworkAvailable(Context ctx) { ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } }