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.app.Activity;

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

public class Main {
    /**
     * Checks whether application has Internet connection.
     */
    public static boolean isConnected(Activity a) {
        ConnectivityManager connMgr = (ConnectivityManager) a.getSystemService(Activity.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected())
            return true;
        else
            return false;
    }
}