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;

import android.util.Log;

public class Main {
    public static boolean CheckNetworkConnect(Context context) {
        boolean result = false;
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        NetworkInfo ethInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
        NetworkInfo activeInfo = manager.getActiveNetworkInfo();
        Log.v("networkInfo", "mobile:" + mobileInfo.isConnected() + "\n" + "wifi:" + wifiInfo.isConnected() + "\n"
                + "eth:" + ethInfo.isConnected() + "\n" + "active:" + activeInfo.getTypeName());
        if (wifiInfo.isConnected() || ethInfo.isConnected()) {
            result = true;
        }
        return result;
    }
}