Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /** * * Check whether network is connected or not * * @param context Context of application * @return true if connected false otherwise */ public static boolean isNetworkAvailable(Context context) { boolean connected = false; ConnectivityManager connectivityManager = null; connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); if (netInfo != null) { connected = netInfo.isConnected(); } return connected; } }