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 isFastDownload(Context ctx) {
    ConnectivityManager mgrConn = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    return mgrConn.getActiveNetworkInfo() != null
            && mgrConn.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED;
    // TelephonyManager mgrTel = (TelephonyManager)
    // ctx.getSystemService(Context.TELEPHONY_SERVICE);
    // || mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) {
}

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.
 *//*  w  w  w.j  a v a 2 s .co  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 isRoaming(Context context) {

    ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    return (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isRoaming());
}

From source file:Main.java

public static boolean isOnWIFI(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting() && ni.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isNetworkConnectet(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnected();
}

From source file:Main.java

public static boolean isOnlineOnWifi(Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo network = cm.getActiveNetworkInfo();

    return network != null && network.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnected();
}

From source file:Main.java

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

From source file:Main.java

static public boolean hasNetworkAccess(Context c) {
    ConnectivityManager network = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = network.getActiveNetworkInfo();
    return info != null && info.isConnected();
}