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:Main.java

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

From source file:Main.java

/**
 * Returns network availability status.//w  ww. j a  v  a2  s .com
 * @param context - Application context.
 * @return - Network availability status.
 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();
    return (info != null && info.isConnected());
}

From source file:Main.java

public static boolean isNetworkAvailable(Context mycontext) {
    ConnectivityManager connectivityManager = (ConnectivityManager) mycontext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isOnWifiInternet(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    return (info.isAvailable() && info.isConnected());
}

From source file:Main.java

public static boolean isMobileConnected(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:Main.java

public static final boolean hasConnectivity(final Context context, final int... networkTypes) {
    final ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (networkTypes.length == 0)
        for (final NetworkInfo info : connectivity.getAllNetworkInfo())
            if (info.isAvailable() || info.isConnected() || info.isConnectedOrConnecting())
                return true;
    for (final int networkType : networkTypes)
        if (ConnectivityManager.isNetworkTypeValid(networkType)) {
            final NetworkInfo info = connectivity.getNetworkInfo(networkType);
            if (info.isAvailable() || info.isConnected() || info.isConnectedOrConnecting())
                return true;
        }/*from w w  w. ja  v  a 2s.c o m*/
    return false;
}

From source file:Main.java

/**
 * Check if device is connected to some network.
 * @param context Context./*from  w  w w  . j a  v a2 s  . c  o m*/
 * @return True if device is connected, False if not.
 */
public static boolean checkConnection(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (mWifi.isConnected())
        return true;
    else
        return false;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isNetworkAvailable(Context c) {
    ConnectivityManager connectivityManager = (ConnectivityManager) c
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean ifWifiConnected(Context context) {
    ConnectivityManager connectionManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiCheck = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiCheck.isConnected();
}