Java Code Examples for com.evernote.android.job.JobRequest#NetworkType
The following examples show how to use
com.evernote.android.job.JobRequest#NetworkType .
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: JobProxy21.java From android-job with Apache License 2.0 | 6 votes |
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) { switch (networkType) { case ANY: return JobInfo.NETWORK_TYPE_NONE; case CONNECTED: return JobInfo.NETWORK_TYPE_ANY; case UNMETERED: return JobInfo.NETWORK_TYPE_UNMETERED; case NOT_ROAMING: return JobInfo.NETWORK_TYPE_UNMETERED; // use unmetered here, is overwritten in v24 case METERED: return JobInfo.NETWORK_TYPE_ANY; // use any here as fallback default: throw new IllegalStateException("not implemented"); } }
Example 2
Source File: JobProxyWorkManager.java From android-job with Apache License 2.0 | 6 votes |
@NonNull private static NetworkType mapNetworkType(@NonNull JobRequest.NetworkType networkType) { switch (networkType) { case ANY: return NetworkType.NOT_REQUIRED; case METERED: return NetworkType.METERED; case CONNECTED: return NetworkType.CONNECTED; case UNMETERED: return NetworkType.UNMETERED; case NOT_ROAMING: return NetworkType.NOT_ROAMING; default: throw new IllegalStateException("Not implemented"); } }
Example 3
Source File: JobProxy26.java From android-job with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Override protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) { switch (networkType) { case METERED: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { return JobInfo.NETWORK_TYPE_CELLULAR; } else { return JobInfo.NETWORK_TYPE_METERED; } default: return super.convertNetworkType(networkType); } }
Example 4
Source File: JobProxy24.java From android-job with Apache License 2.0 | 5 votes |
@Override protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) { switch (networkType) { case NOT_ROAMING: return JobInfo.NETWORK_TYPE_NOT_ROAMING; default: return super.convertNetworkType(networkType); } }
Example 5
Source File: Device.java From android-job with Apache License 2.0 | 5 votes |
/** * Checks the network condition of the device and returns the best type. If the device * is connected to a WiFi and mobile network at the same time, then it would assume * that the connection is unmetered because of the WiFi connection. * * @param context Any context, e.g. the application context. * @return The current network type of the device. */ @NonNull @SuppressWarnings("deprecation") public static JobRequest.NetworkType getNetworkType(@NonNull Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo; try { networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (Throwable t) { return JobRequest.NetworkType.ANY; } if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { return JobRequest.NetworkType.ANY; } boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager); if (!metered) { return JobRequest.NetworkType.UNMETERED; } if (isRoaming(connectivityManager, networkInfo)) { return JobRequest.NetworkType.CONNECTED; } else { return JobRequest.NetworkType.NOT_ROAMING; } }
Example 6
Source File: JobProxyGcm.java From android-job with Apache License 2.0 | 5 votes |
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) { switch (networkType) { case ANY: return Task.NETWORK_STATE_ANY; case CONNECTED: return Task.NETWORK_STATE_CONNECTED; case UNMETERED: return Task.NETWORK_STATE_UNMETERED; case NOT_ROAMING: return Task.NETWORK_STATE_UNMETERED; // use as fallback, NOT_ROAMING not supported default: throw new IllegalStateException("not implemented"); } }
Example 7
Source File: AndroidJobStrategy.java From cloudinary_android with MIT License | 5 votes |
private static JobRequest.NetworkType adaptNetworkType(UploadPolicy.NetworkType networkType) { switch (networkType) { case NONE: return JobRequest.NetworkType.ANY; case ANY: return JobRequest.NetworkType.CONNECTED; case UNMETERED: return JobRequest.NetworkType.UNMETERED; } return JobRequest.NetworkType.ANY; }