check Internet Connection Available - Android Network

Android examples for Network:Network Status

Description

check Internet Connection Available

Demo Code


//package com.java2s;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static boolean checkConnectionAvailable(Context ctx) {
        boolean connected;

        ConnectivityManager connMgr = (ConnectivityManager) ctx
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            connected = true;/*from  www . j  a v  a  2  s. c  o m*/
        } else {
            connected = false;
        }

        return connected;
    }
}

Related Tutorials