Example usage for android.support.v4.net ConnectivityManagerCompat isActiveNetworkMetered

List of usage examples for android.support.v4.net ConnectivityManagerCompat isActiveNetworkMetered

Introduction

In this page you can find the example usage for android.support.v4.net ConnectivityManagerCompat isActiveNetworkMetered.

Prototype

public static boolean isActiveNetworkMetered(ConnectivityManager connectivityManager) 

Source Link

Usage

From source file:com.owncloud.android.utils.ConnectivityUtils.java

public static boolean isAppConnectedViaUnmeteredWiFi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean result = cm != null && cm.getActiveNetworkInfo() != null
            && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
            && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED
            && !ConnectivityManagerCompat.isActiveNetworkMetered(cm);
    Log_OC.d(TAG, "is AppConnectedViaWifi returns " + result);
    return result;
}

From source file:com.nadmm.airports.utils.NetworkUtils.java

public static boolean isConnectedToMeteredNetwork(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return ConnectivityManagerCompat.isActiveNetworkMetered(cm);
}

From source file:org.mariotaku.twidere.util.ImagePreloader.java

public void preloadImage(final String url) {
    if (TextUtils.isEmpty(url))
        return;// www . ja v a2s .co m
    if (ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager)
            && mPreferences.getBoolean(KEY_PRELOAD_WIFI_ONLY, true))
        return;
    mImageLoader.loadImage(url, null);
}

From source file:org.mariotaku.twidere.receiver.ConnectivityStateReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (BuildConfig.DEBUG) {
        Log.d(RECEIVER_LOGTAG, String.format("Received Broadcast %s", intent));
    }//from ww  w.j a v a  2  s. co  m
    if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()))
        return;
    final TwidereApplication application = TwidereApplication.Companion.getInstance(context);
    //        application.reloadConnectivitySettings();
    Utils.startRefreshServiceIfNeeded(application);
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    if (prefs.getBoolean(KEY_USAGE_STATISTICS, false)
            && prefs.getBoolean(KEY_SETTINGS_WIZARD_COMPLETED, false)) {
        // BEGIN HotMobi
        final NetworkEvent event = NetworkEvent.create(context);
        HotMobiLogger.getInstance(context).log(event);
        // END HotMobi
    }

    final Context appContext = context.getApplicationContext();
    final ConnectivityManager cm = (ConnectivityManager) appContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean isNetworkMetered = ConnectivityManagerCompat.isActiveNetworkMetered(cm);
    final boolean isCharging = Utils.isCharging(appContext);
    if (!isNetworkMetered && isCharging) {
        final long currentTime = System.currentTimeMillis();
        final long lastSuccessfulTime = HotMobiLogger.getLastUploadTime(appContext);
        if ((currentTime - lastSuccessfulTime) > HotMobiLogger.UPLOAD_INTERVAL_MILLIS) {
            appContext.startService(new Intent(appContext, UploadLogsService.class));
        }
    }

}

From source file:com.facebook.react.modules.netinfo.NetInfoModule.java

@ReactMethod
public void isConnectionMetered(Promise promise) {
    if (mNoNetworkPermission) {
        promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE, null);
        return;//www  .  j a v  a2  s. c  o m
    }
    promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
}

From source file:com.OpenSource.engine.connectivity.ConnectivityInfoProvider.java

public boolean isActiveNetworkMetered() {
    return ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
}

From source file:androidx.work.impl.constraints.trackers.NetworkStateTracker.java

private NetworkState getActiveNetworkState() {
    // Use getActiveNetworkInfo() instead of getNetworkInfo(network) because it can detect VPNs.
    NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
    boolean isConnected = info != null && info.isConnected();
    boolean isValidated = isActiveNetworkValidated();
    boolean isMetered = ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager);
    boolean isNotRoaming = info != null && !info.isRoaming();
    return new NetworkState(isConnected, isValidated, isMetered, isNotRoaming);
}

From source file:org.jamienicol.episodes.AutoRefreshHelper.java

private boolean checkNetwork() {
    final ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo net = connManager.getActiveNetworkInfo();

    final boolean connected = net != null && net.isConnected();
    final boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connManager);
    final boolean unmeteredOnly = getAutoRefreshWifiOnly();

    final boolean okay = connected && !(metered && unmeteredOnly);

    Log.i(TAG, String.format("connected=%b, metered=%b, unmeteredOnly=%b, checkNetwork() %s.", connected,
            metered, unmeteredOnly, okay ? "passes" : "fails"));

    return okay;//from  ww  w  .  j av  a 2  s.c  om
}

From source file:android_network.hetnet.vpn_service.Util.java

public static boolean isMeteredNetwork(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return (cm != null && ConnectivityManagerCompat.isActiveNetworkMetered(cm));
}

From source file:edu.mit.mobile.android.locast.data.CastMedia.java

/**
 * Attempts to guess if the video player should show a high quality version of the video or a
 * lower bitrate version.//from w w w. ja  v a 2s . c  o m
 *
 * @return true if it seems as though playing high-quality would be expensive or wouldn't work
 */
public static boolean shouldShowLowQuality(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(cm);
    final NetworkInfo net = cm.getActiveNetworkInfo();

    if (metered || net == null || net.isRoaming()) {
        return true;
    }

    // this is because these devices tend to not be able to be powerful enough to show the full
    // res video
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return true;
    }

    final int type = net.getType();

    switch (type) {
    // generally these are fast and cheap/free
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_ETHERNET:
    case ConnectivityManager.TYPE_WIMAX:
        return false;

    default:
        return true;
    }
}