android.support.v4.net.ConnectivityManagerCompat Java Examples
The following examples show how to use
android.support.v4.net.ConnectivityManagerCompat.
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: NetworkReceiver.java From JobSchedulerCompat with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { // Connectivity manager for THIS context - important! final ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = connManager.getActiveNetworkInfo(); if (ensureActiveNetwork(intent, activeNetwork)) { boolean networkUnmetered = false; boolean networkConnected = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); if (networkConnected) { // No point making the call if we know there's no conn. networkUnmetered = !ConnectivityManagerCompat.isActiveNetworkMetered(connManager); } updateTrackedJobs(context, networkConnected, networkUnmetered); } } }
Example #2
Source File: NetInfoModule.java From react-native-GPay with MIT License | 5 votes |
@ReactMethod public void isConnectionMetered(Promise promise) { if (mNoNetworkPermission) { promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE, null); return; } promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager)); }
Example #3
Source File: NetworkReceiver.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
public static void setNetworkForJob(Context context, JobStatus job) { if (job.hasConnectivityConstraint() || job.hasUnmeteredConstraint()) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean networkConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); boolean networkUnmetered = !ConnectivityManagerCompat.isActiveNetworkMetered(cm); job.connectivityConstraintSatisfied.set(networkConnected); job.unmeteredConstraintSatisfied.set(networkUnmetered); } }
Example #4
Source File: ConstraintChecker.java From firebase-jobdispatcher-android with Apache License 2.0 | 4 votes |
/** Returns true if the currently active network is unmetered. */ private static boolean isNetworkUnmetered(ConnectivityManager connectivityManager) { return !ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager); }
Example #5
Source File: Util.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
public static boolean isMeteredNetwork(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return (cm != null && ConnectivityManagerCompat.isActiveNetworkMetered(cm)); }