Android Network State Check isOnline(Context c)

Here you can find the source of isOnline(Context c)

Description

is Online

License

Open Source License

Declaration

public static boolean isOnline(Context c) 

Method Source Code

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

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static boolean isOnline(Context c) {
        boolean haveConnectedWifi = false;
        boolean haveConnectedMobile = false;

        ConnectivityManager cm = (ConnectivityManager) c
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] netInfo = cm.getAllNetworkInfo();
        for (NetworkInfo ni : netInfo) {
            if (ni.getTypeName().equalsIgnoreCase("WIFI"))
                if (ni.isConnected())
                    haveConnectedWifi = true;
            if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
                if (ni.isConnected())
                    haveConnectedMobile = true;
        }//from   w ww . ja v a  2  s .c  o  m
        return haveConnectedWifi || haveConnectedMobile;
    }
}

Related

  1. isConnectingToInternet()
  2. isConnectingToInternet(Context context)
  3. isConnectionFast(int type, int subType)
  4. isNetworkAvailable()
  5. isNetworkConnected(Context context)
  6. isOnline(Context context)
  7. isNetworkReady(Context context)
  8. isConMeNetwork(String ssid)
  9. isConnectNetWork(final Context context)