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 { public static boolean isNetworkAvailable(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { String name = ni.getTypeName(); if (name.equalsIgnoreCase("ETH")) if (ni.isConnected()) return true; if (name.equalsIgnoreCase("WIFI")) if (ni.isConnected()) return true; if (name.equalsIgnoreCase("MOBILE")) if (ni.isConnected()) return true; } return false; } }