Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Copyright 2010 CssWeb Microsystems, Inc. All rights reserved.
 * CssWeb PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * @(#)ActivityUtil.java ?08:07:55 2010-10-3
 */

import android.content.Context;

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

public class Main {
    public static boolean isNetworkAvailable(Context context) {
        ConnectivityManager cn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cn == null) {
            return false;
        }
        NetworkInfo[] netinfo = cn.getAllNetworkInfo();
        if (netinfo == null) {
            return false;
        }
        for (NetworkInfo net : netinfo) {
            if (net.isConnected()) {
                return true;
            }
        }
        return false;
    }
}