Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static boolean isConnectedOrConnecting(Context context) { NetworkInfo[] nets = getConnManager(context).getAllNetworkInfo(); if (nets != null) { NetworkInfo[] networkInfos = nets; int length = nets.length; for (int i = 0; i < length; ++i) { NetworkInfo net = networkInfos[i]; if (net.isConnectedOrConnecting()) { return true; } } } return false; } public static ConnectivityManager getConnManager(Context context) { return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); } }