Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static boolean checkConnection(Activity a) { boolean hasConnectedWifi = false; boolean hasConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("wifi")) if (ni.isConnected()) hasConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("mobile")) if (ni.isConnected()) hasConnectedMobile = true; } return hasConnectedWifi || hasConnectedMobile; } }