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 isOnline(ConnectivityManager connMgr) {
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

From source file:Main.java

static public boolean isNetworkConnectionAvailable(ConnectivityManager connectivityManager) {
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return null != networkInfo && networkInfo.isConnected();
}

From source file:Main.java

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

From source file:Main.java

public static String getNetworkType(ConnectivityManager connManager) {

    NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
    String networkType = null;/*ww w .  j  ava2s . com*/
    if (networkInfo == null) {
        networkType = "not connect";
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        networkType = "wifi";
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        networkType = "mobile";
    }
    return networkType;
}

From source file:Main.java

/**
 * @return {@code true} if device is connected to the Internet,
 * {@code false} otherwise./*from w  w w. j a va 2  s  . co  m*/
 */
public static boolean isOnline(@NonNull ConnectivityManager cm) {
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isWifiConnected(ConnectivityManager cm) {
    if (cm != null) {
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }//from w ww  .  j ava  2  s. co  m
    }
    return false;
}

From source file:Main.java

public static boolean checkIfNetworkConnectionAvailable(ConnectivityManager connManager) {
    boolean isConnected = false;
    NetworkInfo mWifi = connManager.getActiveNetworkInfo();
    if (mWifi != null)
        isConnected = mWifi.isConnected();
    return isConnected;
}

From source file:Main.java

public static boolean isInternetAtiva(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

    return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return (cm.getActiveNetworkInfo() != null) && cm.getActiveNetworkInfo().isConnectedOrConnecting();
}