Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.content.ContextWrapper;

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

public class Main {
    /**
     * Determines if the network is currently available or not.
     * 
     * @param context The context with which to access the system connectivity service
     * @return True if the network is available, false if not
     */
    public static boolean isNetworkAvailable(ContextWrapper context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo network = cm.getActiveNetworkInfo();
        return ((network != null) && (network.isConnected()));
    }
}