Java Code Examples for android.app.job.JobInfo#NETWORK_TYPE_METERED

The following examples show how to use android.app.job.JobInfo#NETWORK_TYPE_METERED . 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: JobProxy26.java    From android-job with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: PlatformScheduler.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("MissingPermission")
private static JobInfo buildJobInfo(
    int jobId,
    ComponentName jobServiceComponentName,
    Requirements requirements,
    String serviceAction,
    String servicePackage) {
  JobInfo.Builder builder = new JobInfo.Builder(jobId, jobServiceComponentName);

  int networkType;
  switch (requirements.getRequiredNetworkType()) {
    case Requirements.NETWORK_TYPE_NONE:
      networkType = JobInfo.NETWORK_TYPE_NONE;
      break;
    case Requirements.NETWORK_TYPE_ANY:
      networkType = JobInfo.NETWORK_TYPE_ANY;
      break;
    case Requirements.NETWORK_TYPE_UNMETERED:
      networkType = JobInfo.NETWORK_TYPE_UNMETERED;
      break;
    case Requirements.NETWORK_TYPE_NOT_ROAMING:
      if (Util.SDK_INT >= 24) {
        networkType = JobInfo.NETWORK_TYPE_NOT_ROAMING;
      } else {
        throw new UnsupportedOperationException();
      }
      break;
    case Requirements.NETWORK_TYPE_METERED:
      if (Util.SDK_INT >= 26) {
        networkType = JobInfo.NETWORK_TYPE_METERED;
      } else {
        throw new UnsupportedOperationException();
      }
      break;
    default:
      throw new UnsupportedOperationException();
  }

  builder.setRequiredNetworkType(networkType);
  builder.setRequiresDeviceIdle(requirements.isIdleRequired());
  builder.setRequiresCharging(requirements.isChargingRequired());
  builder.setPersisted(true);

  PersistableBundle extras = new PersistableBundle();
  extras.putString(KEY_SERVICE_ACTION, serviceAction);
  extras.putString(KEY_SERVICE_PACKAGE, servicePackage);
  extras.putInt(KEY_REQUIREMENTS, requirements.getRequirementsData());
  builder.setExtras(extras);

  return builder.build();
}
 
Example 3
Source File: PlatformScheduler.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("MissingPermission")
private static JobInfo buildJobInfo(
    int jobId,
    ComponentName jobServiceComponentName,
    Requirements requirements,
    String serviceAction,
    String servicePackage) {
  JobInfo.Builder builder = new JobInfo.Builder(jobId, jobServiceComponentName);

  int networkType;
  switch (requirements.getRequiredNetworkType()) {
    case Requirements.NETWORK_TYPE_NONE:
      networkType = JobInfo.NETWORK_TYPE_NONE;
      break;
    case Requirements.NETWORK_TYPE_ANY:
      networkType = JobInfo.NETWORK_TYPE_ANY;
      break;
    case Requirements.NETWORK_TYPE_UNMETERED:
      networkType = JobInfo.NETWORK_TYPE_UNMETERED;
      break;
    case Requirements.NETWORK_TYPE_NOT_ROAMING:
      if (Util.SDK_INT >= 24) {
        networkType = JobInfo.NETWORK_TYPE_NOT_ROAMING;
      } else {
        throw new UnsupportedOperationException();
      }
      break;
    case Requirements.NETWORK_TYPE_METERED:
      if (Util.SDK_INT >= 26) {
        networkType = JobInfo.NETWORK_TYPE_METERED;
      } else {
        throw new UnsupportedOperationException();
      }
      break;
    default:
      throw new UnsupportedOperationException();
  }

  builder.setRequiredNetworkType(networkType);
  builder.setRequiresDeviceIdle(requirements.isIdleRequired());
  builder.setRequiresCharging(requirements.isChargingRequired());
  builder.setPersisted(true);

  PersistableBundle extras = new PersistableBundle();
  extras.putString(KEY_SERVICE_ACTION, serviceAction);
  extras.putString(KEY_SERVICE_PACKAGE, servicePackage);
  extras.putInt(KEY_REQUIREMENTS, requirements.getRequirementsData());
  builder.setExtras(extras);

  return builder.build();
}