is Online - Android Network

Android examples for Network:Network Status

Description

is Online

Demo Code


//package com.java2s;
import android.content.Context;

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

public class Main {
    public static boolean isOnline(Context context) {
        if (context == null) {
            return false;
        }/*  ww  w  . j  a va2 s  .co  m*/
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        return netInfo != null && netInfo.isConnected();
    }
}

Related Tutorials