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 {
    public static final String TAG = "SMUtility";

    /**
     * Checks network availability
     * 
     * @param context
     * @return
     */
    public static boolean isNetworkAvailable(Context context) {
        Log.v(TAG, "isNetworkAvailable called.");
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        if (cm.getActiveNetworkInfo() == null) {
            Log.d(TAG, "no active network info found.");
            return false;
        }

        Log.v(TAG, "active network info found.");
        return cm.getActiveNetworkInfo().isConnectedOrConnecting();
    }
}