Example usage for android.net ConnectivityManager getActiveNetworkInfo

List of usage examples for android.net ConnectivityManager getActiveNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getActiveNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getActiveNetworkInfo() 

Source Link

Document

Returns details about the currently active default data network.

Usage

From source file:Main.java

public static String getCurrentNetwordByName(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    String name = null;/*  ww w .  ja v  a  2  s. c o  m*/
    if (networkInfo != null) {
        name = networkInfo.getTypeName();
    }
    return name;
}

From source file:Main.java

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

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 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";
            }/*www  . j  a  va2s. c  om*/
        }
    }
    return null;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context ctx) {
    if (ctx == null) {
        return false;
    }//from w w  w  .  j  a  va  2 s.  c  o m
    ConnectivityManager connMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkINfo = cm.getActiveNetworkInfo();
    if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }/*from ww w  .j a va2  s.c  o m*/
    return false;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    return isConnected;
}

From source file:Main.java

public static boolean hasNetwork(Context context) {
    ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo workinfo = con.getActiveNetworkInfo();
    if (workinfo == null || !workinfo.isAvailable()) {
        return false;
    } else {/*from   w w w.j a v a2s . c o  m*/
        return true;
    }
}

From source file:Main.java

public static boolean checkMobileNET(Context cxt) {
    ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
        return true;
    else/* ww w . j  ava  2s.  c  o  m*/
        return false;

}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    return connManager.getActiveNetworkInfo() != null && connManager.getActiveNetworkInfo().isConnected();
}