use of com.evernote.android.job.JobRequest in project android by nextcloud.
the class ContactsPreferenceActivity method cancelPreviousContactBackupJobForAccount.
public static void cancelPreviousContactBackupJobForAccount(Context context, Account account) {
Log_OC.d(TAG, "disabling existing contacts backup job for account: " + account.name);
JobManager jobManager = JobManager.create(context);
Set<JobRequest> jobs = jobManager.getAllJobRequestsForTag(ContactsBackupJob.TAG);
for (JobRequest jobRequest : jobs) {
PersistableBundleCompat extras = jobRequest.getExtras();
if (extras.getString(ContactsBackupJob.ACCOUNT, "").equalsIgnoreCase(account.name) && jobRequest.isPeriodic()) {
jobManager.cancel(jobRequest.getJobId());
}
}
}
use of com.evernote.android.job.JobRequest in project ETSMobile-Android2 by ApplETS.
the class BottinSyncJob method scheduleJob.
/**
* Schedule a job if the job hasn't been already scheduled
* Returns the jobId. Returns -1 if no job has been created.
*
* @return the jobId
*/
public static int scheduleJob() {
int jobId = -1;
Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(TAG);
if (jobRequests.isEmpty()) {
jobId = new JobRequest.Builder(TAG).setPeriodic(TimeUnit.DAYS.toMillis(1)).setRequiredNetworkType(JobRequest.NetworkType.CONNECTED).setRequiresBatteryNotLow(true).setRequirementsEnforced(true).setUpdateCurrent(true).build().schedule();
} else {
for (JobRequest jobRequest : jobRequests) {
Log.d(TAG, "Job already scheduled! JobId: " + jobRequest.getJobId() + ". Interval (ms): " + jobRequest.getIntervalMs() + ". Last run: " + jobRequest.getLastRun());
}
}
return jobId;
}
use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class PlatformGcmService method onRunTask.
@Override
public int onRunTask(TaskParams taskParams) {
int jobId = Integer.parseInt(taskParams.getTag());
JobProxy.Common common = new JobProxy.Common(this, CAT, jobId);
JobRequest request = common.getPendingRequest(true, true);
if (request == null) {
return GcmNetworkManager.RESULT_FAILURE;
}
Job.Result result = common.executeJobRequest(request, taskParams.getExtras());
if (Job.Result.SUCCESS.equals(result)) {
return GcmNetworkManager.RESULT_SUCCESS;
} else {
return GcmNetworkManager.RESULT_FAILURE;
}
}
use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class TransientBundleCompatTest method verifyAlarmNotCanceledForPeriodicAfterStart.
@Test
public void verifyAlarmNotCanceledForPeriodicAfterStart() {
assumeTrue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
JobConfig.forceApi(JobApi.V_21);
Bundle extras = new Bundle();
extras.putString("key", "value");
int jobId = new JobRequest.Builder("tag").setPeriodic(TimeUnit.DAYS.toMillis(1)).setTransientExtras(extras).build().schedule();
assertThat(mJobManagerRule.getAllPendingJobsFromScheduler()).isNotNull().isNotEmpty();
JobRequest request = mJobManagerRule.getManager().getJobRequest(jobId);
assertThat(request.isTransient()).isTrue();
final Intent intent = PlatformAlarmServiceExact.createIntent(context(), jobId, null);
PendingIntent pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE);
assertThat(pendingIntent).isNotNull();
boolean started = TransientBundleCompat.startWithTransientBundle(context(), request);
assertThat(started).isTrue();
pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE);
assertThat(pendingIntent).isNotNull();
}
use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class PlatformAlarmService method runJob.
/*package*/
static void runJob(@Nullable Intent intent, @NonNull Service service, @NonNull JobCat cat) {
if (intent == null) {
cat.i("Delivered intent is null");
return;
}
int jobId = intent.getIntExtra(PlatformAlarmReceiver.EXTRA_JOB_ID, -1);
Bundle transientExtras = intent.getBundleExtra(PlatformAlarmReceiver.EXTRA_TRANSIENT_EXTRAS);
final JobProxy.Common common = new JobProxy.Common(service, cat, jobId);
// create the JobManager. Seeing sometimes exceptions, that it wasn't created, yet.
final JobRequest request = common.getPendingRequest(true, true);
if (request != null) {
common.executeJobRequest(request, transientExtras);
}
}
Aggregations