is Network Connected - Android Network

Android examples for Network:Network Status

Description

is Network Connected

Demo Code


//package com.java2s;

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {

    public static boolean isNetworkConnected(Context context) {
        try {/*from www. j  a v  a2 s. co m*/
            ConnectivityManager conn = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo net = conn.getActiveNetworkInfo();
            if (net != null && net.isConnected()) {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
        return false;
    }
}

Related Tutorials