Android examples for Network:Network Status
Checks if network available.
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /**//from ww w . j a va 2 s . com * Checks if network available. * * @param context * @return */ public static boolean isOnline(Context context) { final ConnectivityManager manager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = manager.getActiveNetworkInfo(); return (null != activeNetwork) && activeNetwork.isConnectedOrConnecting(); } }