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.util.Log;

public class Main {
    private static final String TAG = "CommonUtils";

    public static boolean checkConn(Context ctx) {
        ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

        if (conMgr.getNetworkInfo(conMgr.TYPE_MOBILE).isConnectedOrConnecting()
                || conMgr.getNetworkInfo(conMgr.TYPE_WIFI).isConnectedOrConnecting()) {
            Log.v(TAG, "Able to connect to the network");
            return true;
        } else {
            Log.e(TAG, "Unable to connect to network");
        }
        return false;
    }
}