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 isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetworkInfo.isConnected())
        return true;
    return false;
}

From source file:Main.java

/**
 * Returns true if the network is connected.
 * @param context Context associated with the activity.
 *//*  www. j  a v  a 2s  .co m*/
public static boolean isConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiNetworkInfo.isConnected();
}

From source file:Main.java

/**
 * Check whether wifi is enabled and connected
 *
 * @param activity context/*w w w . jav a2s  .com*/
 */
public static boolean isOnline(Context c) {
    ConnectivityManager connMgr = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:Main.java

public static boolean checkNet(Context context) {
    try {/*  w w w  . jav a  2s . c om*/
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:Main.java

public static boolean netWorkCheck(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {
        return info.isConnected();
    } else {//from   w ww  .j  a  v a2s .co  m
        return false;
    }
}

From source file:Main.java

/**
 * Returns {@code true} if there is an active connection.
 *
 * @param context The instance of {@link android.content.Context}.
 * @return {@code true} if there's an active connection, {@code false} otherwise.
 * @throws java.lang.SecurityException If a caller doesn't have the {@link android.Manifest.permission#ACCESS_NETWORK_STATE} permission.
 *///from   w w w. j  a va2 s  .  c o m
public static boolean isConnected(@NonNull final Context context) {
    final Object service = context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final ConnectivityManager cm = (ConnectivityManager) service;
    final NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    try {/* www.ja v  a2 s  .co m*/
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:Main.java

public static boolean checkNetwork(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo != null) {
        if (networkinfo.isConnected()) {
            return true;
        }// w  ww .  j  a va  2s .  c o m
    }
    return false;
}

From source file:Main.java

public static boolean isChargeFreeNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = manager.getActiveNetworkInfo();
    return (activeNetworkInfo != null && activeNetworkInfo.isConnected()
            && (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET));
}