当前位置: 首页>>代码示例>>Java>>正文


Java JobScheduler.getAllPendingJobs方法代码示例

本文整理汇总了Java中android.app.job.JobScheduler.getAllPendingJobs方法的典型用法代码示例。如果您正苦于以下问题:Java JobScheduler.getAllPendingJobs方法的具体用法?Java JobScheduler.getAllPendingJobs怎么用?Java JobScheduler.getAllPendingJobs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.job.JobScheduler的用法示例。


在下文中一共展示了JobScheduler.getAllPendingJobs方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    // If there are not pending jobs. Create a sync job and schedule it.
    List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
    if (pendingJobs.isEmpty()) {
        String inputId = context.getSharedPreferences(SyncJobService.PREFERENCE_EPG_SYNC,
                Context.MODE_PRIVATE).getString(SyncJobService.BUNDLE_KEY_INPUT_ID, null);
        if (inputId != null) {
            // Set up periodic sync only when input has set up.
            SyncUtils.setUpPeriodicSync(context, inputId);
        }
        return;
    }
    // On L/L-MR1, reschedule the pending jobs.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        for (JobInfo job : pendingJobs) {
            if (job.isPersisted()) {
                jobScheduler.schedule(job);
            }
        }
    }
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:25,代码来源:RichBootReceiver.java

示例2: schedule

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
public static void schedule(final Context context) {
    final JobScheduler scheduler = context.getSystemService(JobScheduler.class);

    for (final JobInfo job : scheduler.getAllPendingJobs()) {
        if (job.getId() == JOB_ID_PERIODIC) {
            return;
        }
    }

    final long interval = MINUTE *
            Integer.valueOf(DefaultSharedPrefUtils.getBackgroundServiceInterval(context));

    final ComponentName name = new ComponentName(context, PeriodicJob.class);

    final int result = scheduler.schedule(new JobInfo.Builder(JOB_ID_PERIODIC, name)
            .setPeriodic(interval)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build());

    if (result != JobScheduler.RESULT_SUCCESS) {
        Log.e(TAG, "Failed to schedule periodic job");
    }
}
 
开发者ID:Applications-Development,项目名称:SimpleRssReader,代码行数:25,代码来源:PeriodicJob.java

示例3: testStart

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Test
public void testStart() {
    Context context = InstrumentationRegistry.getTargetContext();
    QuickPeriodicJobScheduler qpjs = new QuickPeriodicJobScheduler(context);
    qpjs.start(2, 30000l);

    SystemClock.sleep(1000);

    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    List<JobInfo> jobInfoList = jobScheduler.getAllPendingJobs();
    JobInfo jobInfo = null;
    for(JobInfo job : jobInfoList) {
        if(job.getId() == 2) {
            jobInfo = job;
        }
    }

    Assert.assertEquals(jobInfo.getMaxExecutionDelayMillis(), 30000l);
    Assert.assertEquals(jobInfo.getMinLatencyMillis(), 30000l);
    Assert.assertEquals(jobInfo.getId(), 2);
    Assert.assertEquals(jobInfo.getExtras().getLong("interval"), 30000l);
    Assert.assertNotNull(jobInfo);
}
 
开发者ID:simplymadeapps,项目名称:QuickPeriodicJobScheduler,代码行数:24,代码来源:InstrumentedTests.java

示例4: onReceive

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    // If there are not pending jobs. Create a sync job and schedule it.
    List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
    if (pendingJobs.isEmpty()) {
        String inputId = context.getSharedPreferences(EpgSyncJobService.PREFERENCE_EPG_SYNC,
                Context.MODE_PRIVATE).getString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, null);
        if (inputId != null) {
            // Set up periodic sync only when input has set up.
            EpgSyncJobService.setUpPeriodicSync(context, inputId,
                    new ComponentName(context, SampleJobService.class));
        }
        return;
    }
    // On L/L-MR1, reschedule the pending jobs.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        for (JobInfo job : pendingJobs) {
            if (job.isPersisted()) {
                jobScheduler.schedule(job);
            }
        }
    }
}
 
开发者ID:googlesamples,项目名称:androidtv-sample-inputs,代码行数:26,代码来源:RichBootReceiver.java

示例5: maybeRetryDownloadDueToGainedConnectivity

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static Intent maybeRetryDownloadDueToGainedConnectivity(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
        for (JobInfo pendingJob : pendingJobs) {
            if (pendingJob.getId() == LOAD_ARTWORK_JOB_ID) {
                return TaskQueueService.getDownloadCurrentArtworkIntent(context);
            }
        }
        return null;
    }
    return (PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0) > 0)
            ? TaskQueueService.getDownloadCurrentArtworkIntent(context)
            : null;
}
 
开发者ID:romannurik,项目名称:muzei,代码行数:17,代码来源:TaskQueueService.java

示例6: createQuoteDownloadJob

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static void createQuoteDownloadJob(Context context, boolean recreate) {
    Xlog.d(TAG, "JobUtils#createQuoteDownloadJob called, recreate == %s", recreate);

    // Instead of canceling the job whenever we disconnect from the
    // internet, we wait until the job executes. Upon execution, we re-check
    // the condition -- if network connectivity has been restored, we just
    // proceed as normal, otherwise, we do not reschedule the task until
    // we receive a network connectivity event.
    if (!shouldRefreshQuote(context)) {
        Xlog.d(TAG, "Should not create job under current conditions, ignoring");
        return;
    }

    JobScheduler scheduler = (JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    // If we're not forcing a job refresh (e.g. when a setting changes),
    // ignore the request if the job already exists
    if (!recreate) {
        for (JobInfo job : scheduler.getAllPendingJobs()) {
            if (job.getId() == JOB_ID) {
                Xlog.d(TAG, "Job already exists and recreate == false, ignoring");
                return;
            }
        }
    }

    int delay = getUpdateDelay(context);
    int networkType = getNetworkType(context);
    JobInfo jobInfo = new JobInfo.Builder(JOB_ID, new ComponentName(context, QuoteDownloaderService.class))
        .setMinimumLatency(delay * 1000)
        .setOverrideDeadline(delay * 1200) // Good balance between battery life and time accuracy
        .setRequiredNetworkType(networkType)
        .build();
    scheduler.schedule(jobInfo);

    Xlog.d(TAG, "Scheduled quote download job with delay: %d", delay);
}
 
开发者ID:apsun,项目名称:QuoteLock,代码行数:38,代码来源:JobUtils.java

示例7: isBeenScheduled

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@TargetApi(21)
public static boolean isBeenScheduled(int JOB_ID, Context context){
    JobScheduler scheduler = (JobScheduler)
            context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    boolean hasBeenScheduled = false;
    for (JobInfo jobInfo : scheduler.getAllPendingJobs()){
        if (jobInfo.getId() == JOB_ID) {
            hasBeenScheduled = true;
        }
    }
    return hasBeenScheduled;
}
 
开发者ID:shier2nd,项目名称:LatestDiscounts,代码行数:13,代码来源:PollJobService.java

示例8: isScheduled

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static boolean isScheduled(Context context) {
    JobScheduler js = context.getSystemService(JobScheduler.class);
    List<JobInfo> jobs = js.getAllPendingJobs();
    if (jobs == null) {
        return false;
    }
    for (int i=0; i<jobs.size(); i++) {
        if (jobs.get(i).getId() == JOB_ID) {
            return true;
        }
    }
    return false;
}
 
开发者ID:dozingcat,项目名称:WireGoggles,代码行数:14,代码来源:NewPictureJob.java

示例9: isScheduled

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static boolean isScheduled(Context context) {
    JobScheduler js = context.getSystemService(JobScheduler.class);
    List<JobInfo> jobs = js.getAllPendingJobs();
    if (jobs == null) {
        return false;
    }
    for (int i=0; i<jobs.size(); i++) {
        if (jobs.get(i).getId() == PHOTOS_CONTENT_JOB) {
            return true;
        }
    }
    return false;
}
 
开发者ID:guardianproject,项目名称:proofmode,代码行数:14,代码来源:PhotosContentJob.java

示例10: isScheduled

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static boolean isScheduled(Context context) {
    JobScheduler js = context.getSystemService(JobScheduler.class);
    List<JobInfo> jobs = js.getAllPendingJobs();
    if (jobs == null) {
        return false;
    }
    for (int i=0; i<jobs.size(); i++) {
        if (jobs.get(i).getId() == CONTENT_JOB_ID) {
            return true;
        }
    }
    return false;
}
 
开发者ID:guardianproject,项目名称:proofmode,代码行数:14,代码来源:VideosContentJob.java

示例11: getAllPendingJobsFromScheduler

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public List<JobInfo> getAllPendingJobsFromScheduler() {
    JobScheduler jobScheduler = getJobScheduler();
    ArrayList<JobInfo> jobs = new ArrayList<>(jobScheduler.getAllPendingJobs());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Iterator<JobInfo> iterator = jobs.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().getId() == JobIdsInternal.JOB_ID_JOB_RESCHEDULE_SERVICE) {
                iterator.remove();
            }
        }
    }
    return jobs;
}
 
开发者ID:evernote,项目名称:android-job,代码行数:15,代码来源:PlatformJobManagerRule.java

示例12: isMediaContentJobServiceRegistered

import android.app.job.JobScheduler; //导入方法依赖的package包/类
/**
 * Method used to verify if the job service is registered.
 *
 * @param context Application context.
 * @return True if the service is registered.
 */
@TargetApi(Build.VERSION_CODES.N)
public boolean isMediaContentJobServiceRegistered(Context context) {
	JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
	List<JobInfo> jobs = js != null ? js.getAllPendingJobs() : null;
	if (jobs != null && !jobs.isEmpty()) {
		for (JobInfo jobInfo : jobs) {
			if (jobInfo.getId() == MediaContentJobService.JOB_ID) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:20,代码来源:DSCApplication.java

示例13: onReceive

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    // If there are not pending jobs. Create a sync job and schedule it.
    List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
    if (pendingJobs.isEmpty()) {
        String inputId = context.getSharedPreferences(EpgSyncJobService.PREFERENCE_EPG_SYNC,
                Context.MODE_PRIVATE).getString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, null);
        if (inputId != null) {
            // Set up periodic sync only when input has set up.
            EpgSyncJobService.setUpPeriodicSync(context, inputId,
                    new ComponentName(context, CumulusJobService.class));
        }
        return;
    }
    // On L/L-MR1, reschedule the pending jobs.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        for (JobInfo job : pendingJobs) {
            if (job.isPersisted()) {
                jobScheduler.schedule(job);
            }
        }
    }

    // Initialize the ChannelDatabase now
    ChannelDatabase.getInstance(context);
}
 
开发者ID:Fleker,项目名称:CumulusTV,代码行数:29,代码来源:TvBootReceiver.java

示例14: runKwotdServiceJob

import android.app.job.JobScheduler; //导入方法依赖的package包/类
protected void runKwotdServiceJob(boolean isOneOffJob) {
  boolean jobAlreadyExists = false;
  JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
  if (!isOneOffJob) {
    // Check if persisted job is already running.
    for (JobInfo jobInfo : scheduler.getAllPendingJobs()) {
      if (jobInfo.getId() == KWOTD_SERVICE_PERSISTED_JOB_ID) {
        // Log.d(TAG, "KWOTD job already exists.");
        jobAlreadyExists = true;
        break;
      }
    }
  }

  // Start job.
  if (!jobAlreadyExists) {
    JobInfo.Builder builder;

    if (isOneOffJob) {
      // A one-off request to the KWOTD server needs Internet access.
      ConnectivityManager cm =
          (ConnectivityManager) getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
        // Inform the user the fetch will happen when there is an Internet connection.
        Toast.makeText(
                this,
                getResources().getString(R.string.kwotd_requires_internet),
                Toast.LENGTH_LONG)
            .show();
      } else {
        // Inform the user operation is under way.
        Toast.makeText(
                this, getResources().getString(R.string.kwotd_fetching), Toast.LENGTH_SHORT)
            .show();
      }

      // Either way, schedule the job for when Internet access is available.
      builder =
          new JobInfo.Builder(
              KWOTD_SERVICE_ONE_OFF_JOB_ID, new ComponentName(this, KwotdService.class));
      builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);

    } else {
      // Set the job to run every 24 hours, during a window with network connectivity, and
      // exponentially back off if it fails with a delay of 1 hour. (Note that Android caps the
      // backoff at 5 hours, so this will retry at 1 hour, 2 hours, and 4 hours, before it
      // gives up.)
      builder =
          new JobInfo.Builder(
              KWOTD_SERVICE_PERSISTED_JOB_ID, new ComponentName(this, KwotdService.class));
      builder.setPeriodic(TimeUnit.HOURS.toMillis(24));
      builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
      builder.setBackoffCriteria(TimeUnit.HOURS.toMillis(1), JobInfo.BACKOFF_POLICY_EXPONENTIAL);
      builder.setRequiresCharging(false);
      builder.setPersisted(true);
    }

    // Pass custom params to job.
    PersistableBundle extras = new PersistableBundle();
    extras.putBoolean(KwotdService.KEY_IS_ONE_OFF_JOB, isOneOffJob);
    builder.setExtras(extras);

    Log.d(TAG, "Scheduling KwotdService job, isOneOffJob: " + isOneOffJob);
    scheduler.schedule(builder.build());
  }
}
 
开发者ID:De7vID,项目名称:klingon-assistant,代码行数:68,代码来源:BaseActivity.java


注:本文中的android.app.job.JobScheduler.getAllPendingJobs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。