Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.net.ConnectivityManager;

public class Main {
    /**
     * Checks if there is any sort of Internet connection
     * @param context
     *          the context in which to check Internet state
     * @return true if connected to Internet, false if not
     */
    public static boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm.getActiveNetworkInfo() == null)
            return false;
        return cm.getActiveNetworkInfo().isConnected();
    }
}