Search in sources :

Example 6 with JobRequest

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());
        }
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) JobManager(com.evernote.android.job.JobManager)

Example 7 with JobRequest

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;
}
Also used : JobRequest(com.evernote.android.job.JobRequest)

Example 8 with JobRequest

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;
    }
}
Also used : JobProxy(com.evernote.android.job.JobProxy) JobRequest(com.evernote.android.job.JobRequest) Job(com.evernote.android.job.Job)

Example 9 with JobRequest

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();
}
Also used : JobRequest(com.evernote.android.job.JobRequest) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Test(org.junit.Test)

Example 10 with JobRequest

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);
    }
}
Also used : JobProxy(com.evernote.android.job.JobProxy) JobRequest(com.evernote.android.job.JobRequest) Bundle(android.os.Bundle)

Aggregations

JobRequest (com.evernote.android.job.JobRequest)10 JobProxy (com.evernote.android.job.JobProxy)5 Bundle (android.os.Bundle)3 Job (com.evernote.android.job.Job)2 JobManager (com.evernote.android.job.JobManager)2 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)2 Test (org.junit.Test)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NonNull (androidx.annotation.NonNull)1 LargeTest (androidx.test.filters.LargeTest)1 WorkInfo (androidx.work.WorkInfo)1