Java Code Examples for android.net.ConnectivityManager#isActiveNetworkMetered()
The following examples show how to use
android.net.ConnectivityManager#isActiveNetworkMetered() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MobileDataPauseDownloadController.java From sketch with Apache License 2.0 | 6 votes |
/** * 网络状态变化或初始化时更新全局暂停功能 * * @param context {@link Context} */ private void updateStatus(@NonNull Context context) { ConnectivityManager connectivityManager = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo networkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null; boolean pause = false; if (networkInfo != null && networkInfo.isAvailable()) { if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { pause = true; } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && connectivityManager.isActiveNetworkMetered()) { pause = true; } } } configuration.setPauseDownloadEnabled(pause); }
Example 2
Source File: AndroidPlatformSupport.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
@Override @SuppressWarnings("deprecation") public boolean connectedToUnmeteredNetwork() { //Returns true if using unmetered connection, use shortcut method if available ConnectivityManager cm = (ConnectivityManager) AndroidGame.instance.getSystemService(Context.CONNECTIVITY_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ return !cm.isActiveNetworkMetered(); } else { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting() && (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI || activeNetwork.getType() == ConnectivityManager.TYPE_WIMAX || activeNetwork.getType() == ConnectivityManager.TYPE_BLUETOOTH || activeNetwork.getType() == ConnectivityManager.TYPE_ETHERNET); } }
Example 3
Source File: Requirements.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@RequirementFlags private int getNotMetNetworkRequirements(Context context) { if (!isNetworkRequired()) { return 0; } ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = Assertions.checkNotNull(connectivityManager).getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected() || !isInternetConnectivityValidated(connectivityManager)) { return requirements & (NETWORK | NETWORK_UNMETERED); } if (isUnmeteredNetworkRequired() && connectivityManager.isActiveNetworkMetered()) { return NETWORK_UNMETERED; } return 0; }
Example 4
Source File: Requirements.java From MediaSDK with Apache License 2.0 | 6 votes |
@RequirementFlags private int getNotMetNetworkRequirements(Context context) { if (!isNetworkRequired()) { return 0; } ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = Assertions.checkNotNull(connectivityManager).getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected() || !isInternetConnectivityValidated(connectivityManager)) { return requirements & (NETWORK | NETWORK_UNMETERED); } if (isUnmeteredNetworkRequired() && connectivityManager.isActiveNetworkMetered()) { return NETWORK_UNMETERED; } return 0; }
Example 5
Source File: Requirements.java From Telegram with GNU General Public License v2.0 | 6 votes |
@RequirementFlags private int getNotMetNetworkRequirements(Context context) { if (!isNetworkRequired()) { return 0; } ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = Assertions.checkNotNull(connectivityManager).getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected() || !isInternetConnectivityValidated(connectivityManager)) { return requirements & (NETWORK | NETWORK_UNMETERED); } if (isUnmeteredNetworkRequired() && connectivityManager.isActiveNetworkMetered()) { return NETWORK_UNMETERED; } return 0; }
Example 6
Source File: Requirements.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static boolean isActiveNetworkMetered( ConnectivityManager connectivityManager, NetworkInfo networkInfo) { if (Util.SDK_INT >= 16) { return connectivityManager.isActiveNetworkMetered(); } int type = networkInfo.getType(); return type != ConnectivityManager.TYPE_WIFI && type != ConnectivityManager.TYPE_BLUETOOTH && type != ConnectivityManager.TYPE_ETHERNET; }
Example 7
Source File: HttpService.java From MiPushFramework with GNU General Public License v3.0 | 5 votes |
@SuppressLint({"NewApi"}) public boolean isUnmeteredNetworkConnected() { ConnectivityManager connectivityManager = (ConnectivityManager) HttpService.this.getApplicationContext().getSystemService("connectivity"); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.getType() == 1) { return true; } if (VERSION.SDK_INT >= 16) { return !connectivityManager.isActiveNetworkMetered(); } } return false; }
Example 8
Source File: NetworkUtil.java From YalpStore with GNU General Public License v2.0 | 5 votes |
static public boolean isMetered(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE); if (null == connectivityManager) { return true; } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { return isActiveNetworkMetered(connectivityManager); } else { return connectivityManager.isActiveNetworkMetered(); } }
Example 9
Source File: SnippetsLauncher.java From 365browser with Apache License 2.0 | 5 votes |
@CalledByNative public boolean isOnUnmeteredConnection() { Context context = ContextUtils.getApplicationContext(); ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return !manager.isActiveNetworkMetered(); }
Example 10
Source File: RunConditionMonitor.java From syncthing-android with Mozilla Public License 2.0 | 5 votes |
private boolean isMeteredNetworkConnection() { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni == null) { // In flight mode. return false; } if (!ni.isConnected()) { // No network connection. return false; } return cm.isActiveNetworkMetered(); }
Example 11
Source File: IsConnectedUnMeteredOrUnknown.java From SnackEngage with MIT License | 5 votes |
@SuppressLint("MissingPermission") protected boolean checkConnection(@NonNull final ConnectivityManager cm, @NonNull final NetworkInfo activeNetwork) { if (Build.VERSION.SDK_INT >= 16) { return !cm.isActiveNetworkMetered(); } return activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; }
Example 12
Source File: ConnectivityManagerCompatJellyBean.java From V.FlyoutTest with MIT License | 4 votes |
public static boolean isActiveNetworkMetered(ConnectivityManager cm) { return cm.isActiveNetworkMetered(); }
Example 13
Source File: h.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
public static boolean a(ConnectivityManager connectivitymanager) { return connectivitymanager.isActiveNetworkMetered(); }
Example 14
Source File: DownloadManagerService.java From 365browser with Apache License 2.0 | 4 votes |
static boolean isActiveNetworkMetered(Context context) { if (sIsNetworkListenerDisabled) return sIsNetworkMetered; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.isActiveNetworkMetered(); }
Example 15
Source File: DownloadManagerService.java From AndroidChromium with Apache License 2.0 | 4 votes |
static boolean isActiveNetworkMetered(Context context) { if (sIsNetworkListenerDisabled) return sIsNetworkMetered; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.isActiveNetworkMetered(); }
Example 16
Source File: ConnectivityManagerCompatJellyBean.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public static boolean isActiveNetworkMetered(ConnectivityManager cm) { return cm.isActiveNetworkMetered(); }
Example 17
Source File: DownloadManagerService.java From delion with Apache License 2.0 | 4 votes |
static boolean isActiveNetworkMetered(Context context) { if (sIsNetworkListenerDisabled) return sIsNetworkMetered; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.isActiveNetworkMetered(); }
Example 18
Source File: DeviceUtils.java From JobSchedulerCompat with MIT License | 4 votes |
public static boolean isMetered(Context context) { ConnectivityManager manager = getConnectivityManager(context); NetworkInfo info = getActiveNetworkInfo(manager); return info != null && info.isConnected() && manager.isActiveNetworkMetered(); }
Example 19
Source File: DeviceUtils.java From JobSchedulerCompat with MIT License | 4 votes |
public static boolean isUnmetered(Context context) { ConnectivityManager manager = getConnectivityManager(context); NetworkInfo info = getActiveNetworkInfo(manager); return info != null && info.isConnected() && !manager.isActiveNetworkMetered(); }
Example 20
Source File: ConnectivityManagerCompatJellyBean.java From guideshow with MIT License | 4 votes |
public static boolean isActiveNetworkMetered(ConnectivityManager cm) { return cm.isActiveNetworkMetered(); }