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;
import android.net.NetworkInfo;

public class Main {
    /**
     * Detects the availability of a working Wifi network connection to open a
     * http/https connection.
     *
     * @param context The context of the activity who is trying to check for the
     *                status of the network.
     * @return true if Wifi network is available, false otherwise.
     */
    public static boolean isWiFiAvailable(Context context) {
        if (context == null)
            return false;

        ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiNetwork = conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetwork != null && wifiNetwork.isConnected()) {
            return true;
        } else {
            return false;
        }

    }
}