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