Example usage for android.net NetworkInfo isConnected

List of usage examples for android.net NetworkInfo isConnected

Introduction

In this page you can find the example usage for android.net NetworkInfo isConnected.

Prototype

@Deprecated
public boolean isConnected() 

Source Link

Document

Indicates whether network connectivity exists and it is possible to establish connections and pass data.

Usage

From source file:com.geekytheory.miguelcatalandev.developerdays.Main_Fragment_Social.java

public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getView().getContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        return true;
    }/*from   ww  w. java 2s  .c om*/
    return false;
}

From source file:it.sasabz.android.sasabus.classes.hafas.XMLAsyncRequest.java

/**
 * this method checks if a networkconnection is active or not
 * @return boolean if the network is reachable or not
 *//*from  w w  w. j  av a2 s .  c o m*/
private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) (activity.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        //testing WIFI connection
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:it.sasabz.android.sasabus.InfoActivity.java

/**
* this method checks if a networkconnection is active or not
* @return boolean if the network is reachable or not
*///ww w .  j av  a 2 s. c o  m
private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) (this.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        //testing WIFI connection
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:helper.util.RESTClient.java

/**
 * Helper function for checking of network availability. Class must have initialized
 * _context, otherwise it will not work.
 * @return boolean status of network connection
 *///  www .  ja va  2  s .  c  om
private boolean networkAvailable() {
    ConnectivityManager cm = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    // if no network is available networkInfo will be null
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }
    return false;
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment51.java

public boolean isConnection() {
    ConnectivityManager connMgr = (ConnectivityManager) getActivity()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

From source file:com.gameanalytics.android.BatchThread.java

private boolean isNetworkConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:palamarchuk.fraudguide.utils.QueryMaster.java

private boolean isNetworkConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:com.android.googlesearch.SuggestionProvider.java

private boolean isNetworkConnected() {
    NetworkInfo networkInfo = getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

From source file:jieehd.villain.updater.checkInBackground.java

public boolean haveNetworkConnection(Context mContext) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) mContext.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 w w.ja  v a2 s.  c  o m
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:org.ametro.app.ApplicationEx.java

public boolean isNetworkAvailable() {
    NetworkInfo[] infs = mConnectionManager.getAllNetworkInfo();
    if (infs != null && infs.length > 0) {
        for (NetworkInfo inf : infs) {
            if (inf.isConnected()) {
                return true;
            }/* ww w  .  j a  v  a 2  s  .  co m*/
        }
    }
    return false;
}