Android Network State Check isNetAvailable(Context context)

Here you can find the source of isNetAvailable(Context context)

Description

Checks if Network connectivity is available to download OpenCellID data

License

Open Source License

Declaration

public static Boolean isNetAvailable(Context context) 

Method Source Code

//package com.java2s;
/**   Copyright (C) 2013  Louis Teboul (a.k.a Androguide)
 *
 *    admin@pimpmyrom.org  || louisteboul@gmail.com
 *    http://pimpmyrom.org || http://androguide.fr
 *    71 quai Cl?menceau, 69300 Caluire-et-Cuire, FRANCE.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License along
 *      with this program; if not, write to the Free Software Foundation, Inc.,
 *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **///from   w  w w .j a v a 2  s.c om

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**
     * Checks if Network connectivity is available to download OpenCellID data
     */
    public static Boolean isNetAvailable(Context context) {

        try {
            ConnectivityManager connectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo wifiInfo = connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            NetworkInfo mobileInfo = connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            if (wifiInfo != null && mobileInfo != null) {
                return wifiInfo.isConnected() || mobileInfo.isConnected();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. isNetworkAvailable(Context context)
  2. isMobileOnline(Context context)
  3. isInternetReachable(Context context)
  4. isHightBandwidthConnection(Context context)
  5. isConnectionFast(int type, int subType)
  6. isNetworkAvailable(Context context)
  7. isNetworkAvailable(Context context)
  8. isNetworkAvailable(Context context)
  9. isNetworkAvailable(Context paramContext)