FileDocCategorySizeDatePackage
ConnectivityManagerCompat.javaAPI DocAndroid 5.1 API4464Thu Mar 12 22:22:56 GMT 2015android.support.v4.net

ConnectivityManagerCompat

public class ConnectivityManagerCompat extends Object
Helper for accessing features in {@link ConnectivityManager} introduced after API level 16 in a backwards compatible fashion.

Fields Summary
private static final ConnectivityManagerCompatImpl
IMPL
Constructors Summary
Methods Summary
public static android.net.NetworkInfogetNetworkInfoFromBroadcast(android.net.ConnectivityManager cm, android.content.Intent intent)
Return the {@link NetworkInfo} that caused the given {@link ConnectivityManager#CONNECTIVITY_ACTION} broadcast. This obtains the current state from {@link ConnectivityManager} instead of using the potentially-stale value from {@link ConnectivityManager#EXTRA_NETWORK_INFO}. May be {@code null}.

        final NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        if (info != null) {
            return cm.getNetworkInfo(info.getType());
        } else {
            return null;
        }
    
public static booleanisActiveNetworkMetered(android.net.ConnectivityManager cm)
Returns if the currently active data network is metered. A network is classified as metered when the user is sensitive to heavy data usage on that connection. You should check this before doing large data transfers, and warn the user or delay the operation until another network is available.

        if (Build.VERSION.SDK_INT >= 16) {
            IMPL = new JellyBeanConnectivityManagerCompatImpl();
        } else if (Build.VERSION.SDK_INT >= 13) {
            IMPL = new HoneycombMR2ConnectivityManagerCompatImpl();
        } else if (Build.VERSION.SDK_INT >= 8) {
            IMPL = new GingerbreadConnectivityManagerCompatImpl();
        } else {
            IMPL = new BaseConnectivityManagerCompatImpl();
        }
    
        return IMPL.isActiveNetworkMetered(cm);