Example usage for android.net NetworkInfo isAvailable

List of usage examples for android.net NetworkInfo isAvailable

Introduction

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

Prototype

@Deprecated
public boolean isAvailable() 

Source Link

Document

Indicates whether network connectivity is possible.

Usage

From source file:Main.java

public static boolean isWifiNetwrokType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();

    if (info != null && info.isAvailable()) {
        if (info.getTypeName().equalsIgnoreCase("wifi")) {
            return true;
        }//from  w w w .  j ava  2s  . com
    }
    return false;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = (cm != null) ? cm.getActiveNetworkInfo() : null;
    if (info != null && info.isAvailable() && info.isConnected()) {
        return true;
    }/* w  w  w. j  a  v  a2  s. c  o m*/

    return false;
}

From source file:Main.java

public static boolean isNetWorkConnected(Context context) {
    if (context == null)
        return false;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info != null)
        return info.isAvailable();
    return false;
}

From source file:Main.java

public static boolean is4G(Context context) {
    NetworkInfo info = getActiveNetworkInfo(context);
    return info != null && info.isAvailable() && info.getSubtype() == TelephonyManager.NETWORK_TYPE_LTE;
}

From source file:Main.java

public static boolean isAvailable(Context context) {
    NetworkInfo info = getActiveNetworkInfo(context);
    return info != null && info.isAvailable();
}

From source file:Main.java

public static boolean CheckNet(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }//from w  w w. j a v a 2  s .  c  o  m
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;
}

From source file:Main.java

public static String currentNetwork(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {
        if (info.isAvailable() && info.isConnectedOrConnecting()) {
            String netType = info.getTypeName();
            if ("WIFI".equals(netType)) {
                return "WIFI";
            } else {
                return "2G/3G";
            }/*w w  w.  j  a  v  a2  s.  c  o  m*/
        }
    }
    return null;
}

From source file:Main.java

public static boolean checkNetwork(Context context) {
    ConnectivityManager netManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = netManager.getActiveNetworkInfo();
    if (info != null)
        return info.isAvailable();
    else/*ww w.ja  v a 2  s  . c o m*/
        return false;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(Context ctx) {
    ConnectivityManager manager = (ConnectivityManager) ctx.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }// w  w w  .  j ava2 s  . com
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;
}