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:fr.pingtimeout.ConnectionUtils.java

public static boolean isOnWifi(Context context) {
    Log.d(loggerName, "Checking if connection is Wifi");

    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (wifiNetworkInfo.isConnected()) {
        Log.d(loggerName, "Wifi is connected");
        return true;
    } else {//from w w  w. j  a v a 2  s .co m
        Log.d(loggerName, "Wifi is not connected");
        return false;
    }
}

From source file:com.android.utility.util.Network.java

/**
 * Check if data connection is available.
 * /*from   w w  w . j  a va 2 s .c om*/
 * @param context
 * @return
 */
public static boolean isDataConnectionAvailable(Context context) {
    if (context == null) {
        throw new IllegalArgumentException();
    }

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    return ((netInfo != null) && netInfo.isConnected());
}

From source file:com.saltedge.sdk.network.SERestClient.java

/**
 * Check if networks are available.//w  w  w.j  av  a2 s .  co  m
 *
 * @return true if networks are available, false if not
 */
private static boolean isNetworkUnavailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) SaltEdgeSDK.getInstance().getContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return (activeNetworkInfo == null || !activeNetworkInfo.isConnected());
}

From source file:Main.java

/**
 * checks if there is WI-FI or network connection available
 * @param currentActivity// w w w . j  av  a 2 s  .c  om
 * @return
 */
public static boolean isInternetAvailable(Context currentActivity) {
    final ConnectivityManager conectivityManager = (ConnectivityManager) currentActivity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            if (networkInfo.isConnected()) {
                return true;
            }
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            if (networkInfo.isConnected()) {
                return true;
            }
        }
    }

    return false;
}

From source file:in.huohua.peterson.network.NetworkUtils.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return (info != null && info.isConnected());
}

From source file:Main.java

public static boolean checkWifiInternetConn() {
    //Create object for ConnectivityManager class which returns network related info
    ConnectivityManager connectivity = (ConnectivityManager) m_TempContext
            .getSystemService(m_TempContext.CONNECTIVITY_SERVICE);
    //If connectivity object is not null
    if (connectivity != null) {
        //Get network info - WIFI internet access
        NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (info != null) {
            //Look for whether device is currently connected to WIFI network
            if (info.isConnected()) {
                return true;
            }//from  w  w  w.j av a  2  s.c om
        }
    }
    return false;
}

From source file:Main.java

public static boolean checkMobileInternetConn() {
    //Create object for ConnectivityManager class which returns network related info
    ConnectivityManager connectivity = (ConnectivityManager) m_TempContext
            .getSystemService(m_TempContext.CONNECTIVITY_SERVICE);
    //If connectivity object is not null
    if (connectivity != null) {
        //Get network info - Mobile internet access
        NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (info != null) {
            //Look for whether device is currently connected to Mobile internet
            if (info.isConnected()) {
                return true;
            }//from   w ww.j  a  va  2  s .c  om
        }
    }
    return false;
}

From source file:mc.lib.network.NetworkHelper.java

public static boolean hasConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni != null && ni.isAvailable() && ni.isConnected()) {
        if (testConnection(TEST_SERVER1) || testConnection(TEST_SERVER2) || testConnection(TEST_SERVER3)) {
            Log.i(LOGTAG, "Internet connection detected");
            return true;
        }/* w w  w.  j av a 2s  .c o  m*/
    }

    Log.i(LOGTAG, "No internet connection detected");
    return false;
}

From source file:com.ilearnrw.reader.utils.HttpHelper.java

public static boolean isNetworkAvailable(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return (ni != null) && (ni.isConnected());
}

From source file:Main.java

public static boolean isConnectedWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = null;
    if (connectivityManager != null) {
        networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    }//from ww  w  .j a v  a 2 s .c  om

    return networkInfo == null ? false : networkInfo.isConnected();
}