Java tutorial
//package com.java2s; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static boolean isNetworkAvailable(ConnectivityManager cm) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; NetworkInfo[] mNetInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : mNetInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } }