Android Network State Check CheckInternet(Activity a)

Here you can find the source of CheckInternet(Activity a)

Description

Check Internet

License

Open Source License

Declaration

public static boolean CheckInternet(Activity a) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;

import android.content.Context;

import android.net.ConnectivityManager;

public class Main {

    public static boolean CheckInternet(Activity a) {
        ConnectivityManager connec = (ConnectivityManager) a
                .getBaseContext().getSystemService(
                        Context.CONNECTIVITY_SERVICE);
        android.net.NetworkInfo wifi = connec
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        android.net.NetworkInfo mobile = connec
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (wifi.isConnected()) {
            return true;
        } else if (mobile.isConnected()) {
            return true;
        }//ww  w.  j  a  v  a 2s .c  om
        return false;
    }
}

Related

  1. setMobileDataEnabled(Activity a, Context context, boolean enabled)
  2. isNetworkAvailable(Activity mainActivity)
  3. isDeviceOnline(Activity activity)
  4. isConnected(final Activity act)
  5. isOnline(Activity activity)
  6. checkInternetConnection(Context context)