Checks if network available. - Android Network

Android examples for Network:Network Status

Description

Checks if network available.

Demo Code


//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();
    }
}

Related Tutorials