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 boolean isWiFiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo.getType() == ConnectivityManager.TYPE_WIFI ? true : false;
}

From source file:Main.java

public static boolean isNetConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        return true;
    }/*from   w  w  w.  jav  a  2  s .  c o m*/
    return false;
}

From source file:Main.java

public static boolean isconnected(Context applicationContext) {

    ConnectivityManager cm = (ConnectivityManager) applicationContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNW = cm.getActiveNetworkInfo();
    boolean isConnected = false;
    if (activeNW != null) {
        isConnected = activeNW.isConnectedOrConnecting();
    }/* www.  j  a v a 2 s .  com*/
    return isConnected;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    if (hasPermission(context, "android.permission.ACCESS_NETWORK_STATE") == false) {
        return true;
    }//from  w  w w .j av  a 2 s.  c  o m
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getActiveNetworkInfo() != null
            && connectivityManager.getActiveNetworkInfo().isAvailable()
            && connectivityManager.getActiveNetworkInfo().isConnected()) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    return (activeNetInfo != null) && (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI);
}

From source file:Main.java

public static int isHightBandwidthConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return isConnectionFast(info.getType(), info.getSubtype());
}

From source file:Main.java

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

    if (cm == null)
        return false;
    return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;

}

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;
        }/*ww w  .  j  av  a  2 s .  co m*/
    }
    return false;
}

From source file:Main.java

public static boolean checkNetwork(Context ctx) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mNetworkInfo != null)
        return mNetworkInfo.isAvailable();
    return false;
}

From source file:Main.java

public static boolean isNetworkReachable(Context mContext) {
    boolean bRet = false;
    try {/*from   w w  w .j a  v  a  2s . com*/
        ConnectivityManager conn = (ConnectivityManager) mContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = conn.getActiveNetworkInfo();
        bRet = (null == netInfo) ? false : netInfo.isAvailable();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bRet;
}