本文整理汇总了Java中android.app.job.JobInfo类的典型用法代码示例。如果您正苦于以下问题:Java JobInfo类的具体用法?Java JobInfo怎么用?Java JobInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JobInfo类属于android.app.job包,在下文中一共展示了JobInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSharedPreferenceChanged
import android.app.job.JobInfo; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
final String remindersKey = getString(R.string.pref_key_reminders);
if (key.equals(remindersKey)) {
boolean enabled = sharedPreferences.getBoolean(remindersKey, false);
JobScheduler jobScheduler =
(JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (!enabled) {
jobScheduler.cancel(JOB_ID);
Log.d(TAG, "cancelling scheduled job");
} else {
long interval = AlarmManager.INTERVAL_HOUR;
JobInfo job = new JobInfo.Builder(JOB_ID,
new ComponentName(getPackageName(),
ScheduledJobService.class.getName()))
.setPersisted(true)
.setPeriodic(interval)
.build();
jobScheduler.schedule(job);
Log.d(TAG, "setting scheduled job for: " + interval);
}
}
}
示例2: requestSync
import android.app.job.JobInfo; //导入依赖的package包/类
public static void requestSync(Context context, String inputId, boolean currentProgramOnly) {
PersistableBundle pBundle = new PersistableBundle();
pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
pBundle.putString(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
pBundle.putBoolean(SyncJobService.BUNDLE_KEY_CURRENT_PROGRAM_ONLY, currentProgramOnly);
JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID,
new ComponentName(context, SyncJobService.class));
JobInfo jobInfo = builder
.setExtras(pBundle)
.setOverrideDeadline(SyncJobService.OVERRIDE_DEADLINE_MILLIS)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
scheduleJob(context, jobInfo);
Intent intent = new Intent(SyncJobService.ACTION_SYNC_STATUS_CHANGED);
intent.putExtra(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
intent.putExtra(SyncJobService.SYNC_STATUS, SyncJobService.SYNC_STARTED);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
示例3: onReceive
import android.app.job.JobInfo; //导入依赖的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);
}
}
}
}
示例4: scheduleAddWatchNextRequest
import android.app.job.JobInfo; //导入依赖的package包/类
public static void scheduleAddWatchNextRequest(Context context, ClipData clipData) {
JobScheduler scheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
PersistableBundle bundle = new PersistableBundle();
bundle.putString(ID_KEY, clipData.getClipId());
bundle.putString(CONTENT_ID_KEY, clipData.getContentId());
bundle.putLong(DURATION_KEY, clipData.getDuration());
bundle.putLong(PROGRESS_KEY, clipData.getProgress());
bundle.putString(TITLE_KEY, clipData.getTitle());
bundle.putString(DESCRIPTION_KEY, clipData.getDescription());
bundle.putString(CARD_IMAGE_URL_KEY, clipData.getCardImageUrl());
scheduler.schedule(new JobInfo.Builder(1,
new ComponentName(context, AddWatchNextService.class))
.setMinimumLatency(0)
.setExtras(bundle)
.build());
}
示例5: schedule
import android.app.job.JobInfo; //导入依赖的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");
}
}
示例6: onCreate
import android.app.job.JobInfo; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Create JobScheduler
JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
//Create a component passing the JobService that we want to use
ComponentName jobService = new ComponentName(getPackageName(), MyJobService.class.getName());
//Create a JobInfo passing a unique JOB_ID and the jobService
//also set the periodic time to repeat this job
JobInfo jobInfo = new JobInfo.Builder(JOB_ID, jobService)
.setPeriodic(REFRESH_INTERVAL)
.build();
jobScheduler.schedule(jobInfo);
}
示例7: testProcessOnePacket
import android.app.job.JobInfo; //导入依赖的package包/类
@Test(timeout = 5000)
public void testProcessOnePacket() throws Exception {
DataPacket dataPacket = new ByteArrayDataPacket(Collections.singletonMap("id", "testId"), "testPayload".getBytes(Charsets.UTF_8));
queuedSiteToSiteClientConfig.createQueuedClient(context).enqueue(dataPacket);
mockNiFiS2SServer.enqueueSiteToSitePeers(Collections.singletonList(peer));
String transactionPath = mockNiFiS2SServer.enqueuCreateTransaction(portIdentifier, transactionIdentifier, 30);
mockNiFiS2SServer.enqueuDataPackets(transactionPath, Collections.singletonList(dataPacket), queuedSiteToSiteClientConfig);
mockNiFiS2SServer.enqueueTransactionComplete(transactionPath, 2, ResponseCode.CONFIRM_TRANSACTION, ResponseCode.CONFIRM_TRANSACTION);
JobInfo.Builder processJobInfoBuilder = SiteToSiteJobService.createProcessJobInfoBuilder(context, 1, queuedSiteToSiteClientConfig, parcelableQueuedOperationResultCallback);
processJobInfoBuilder.setOverrideDeadline(0);
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
assertEquals(JobScheduler.RESULT_SUCCESS, jobScheduler.schedule(processJobInfoBuilder.build()));
assertEquals(1, parcelableQueuedOperationResultCallback.getInvocations().size());
SiteToSiteDBTestUtil.assertNoQueuedPackets(siteToSiteDB);
mockNiFiS2SServer.verifyAssertions();
}
示例8: schedule
import android.app.job.JobInfo; //导入依赖的package包/类
@Override
public int schedule(JobInfo job) throws RemoteException {
int vuid = VBinder.getCallingUid();
int id = job.getId();
ComponentName service = job.getService();
JobId jobId = new JobId(vuid, service.getPackageName(), id);
JobConfig config = mJobStore.get(jobId);
if (config == null) {
config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras());
mJobStore.put(jobId, config);
} else {
config.serviceName = service.getClassName();
config.extras = job.getExtras();
}
saveJobs();
mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId);
mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent);
return mScheduler.schedule(job);
}
示例9: testStart
import android.app.job.JobInfo; //导入依赖的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);
}
示例10: schedule
import android.app.job.JobInfo; //导入依赖的package包/类
public void schedule(int time, boolean startOnBoot) {
if (mAlarm == null) {
JobInfo.Builder job = new JobInfo.Builder(1, new ComponentName(mContext, NotificationsJS.class));
PersistableBundle pb = new PersistableBundle();
pb.putInt("JobSyncTime", time);
job.setPersisted(startOnBoot)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setMinimumLatency(time)
.setExtras(pb);
if (connected())
if (syncExact == 1)
job.setOverrideDeadline(time);
else
job.setOverrideDeadline(time * 2);
mJobScheduler.schedule(job.build());
Log.i("MFB_Scheduler", "JobScheduler started");
} else {
syncTime = time;
receiver = new Receiver();
IntentFilter filter = new IntentFilter();
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
mContext.getPackageManager().setComponentEnabledSetting(new ComponentName(mContext, Receiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
mContext.registerReceiver(receiver, filter);
Log.i("MFB_Scheduler", "AlarmManager started");
}
}
示例11: schedule
import android.app.job.JobInfo; //导入依赖的package包/类
public static void schedule(Context context) {
SharedPreferences settings = AppSettings.getSharedPreferences(context);
int notificationsFrequency = AppSettings.Notifications.getNotificationsFrequency(settings);
ComponentName component = new ComponentName(context, NotificationsJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, component)
.setPeriodic(60000 * notificationsFrequency);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NOT_ROAMING);
else
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
}
示例12: startPolling
import android.app.job.JobInfo; //导入依赖的package包/类
@TargetApi(21)
public static void startPolling(Context context) {
JobScheduler scheduler = (JobScheduler)
context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
final int JOB_ID = 1;
if (isBeenScheduled(JOB_ID, context)){
Log.i(TAG, "scheduler.cancel(JOB_ID)");
scheduler.cancel(JOB_ID);
} else{
Log.i(TAG, "scheduler.schedule(jobInfo)");
int pollInterval = QueryPreferences.getPollInterval(context);
Log.i(TAG, "the poll interval is: " + pollInterval + " ms");
JobInfo jobInfo = new JobInfo.Builder(
JOB_ID, new ComponentName(context, PollJobService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setPeriodic(pollInterval)
.setPersisted(true)
.build();
scheduler.schedule(jobInfo);
}
}
示例13: onBindViewHolder
import android.app.job.JobInfo; //导入依赖的package包/类
@Override
public void onBindViewHolder(JobListRecyclerAdapter.JobViewHolder holder, int position) {
final JobInfo ji= mJobList.get(position);
holder.jobId.setText(Integer.toString(ji.getId()));
holder.serviceName.setText(ji.getService().getClassName());
holder.stopBut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
JobScheduler jobScheduler = (JobScheduler)mContext.getSystemService(mContext.JOB_SCHEDULER_SERVICE);
jobScheduler.cancel(ji.getId());
Log.i("JobList", "Stopping the job "+ji.getId());
Toast.makeText(mContext,
"Canceling the job "+ji.getId(),
Toast.LENGTH_LONG).show();
mContext.initList();
}
});
}
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:20,代码来源:JobListRecyclerAdapter.java
示例14: schedulePeriodic
import android.app.job.JobInfo; //导入依赖的package包/类
private static void schedulePeriodic(Context context) {
Timber.d("Scheduling a periodic task");
JobInfo.Builder builder = new JobInfo.Builder(
PERIODIC_ID, new ComponentName(context, QuoteJobService.class));
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(PERIOD)
.setBackoffCriteria(INITIAL_BACKOFF, JobInfo.BACKOFF_POLICY_EXPONENTIAL);
JobScheduler scheduler = (JobScheduler) context.getSystemService(
Context.JOB_SCHEDULER_SERVICE);
int result = scheduler.schedule(builder.build());
if (result == JobScheduler.RESULT_SUCCESS) {
Timber.i("Job scheduled successfully!");
} else {
Timber.e("Job did not scheduled!");
}
}
示例15: syncJob
import android.app.job.JobInfo; //导入依赖的package包/类
private void syncJob() {
QiscusAccount qiscusAccount = Qiscus.getQiscusAccount();
Random rand = new Random();
int randomValue = rand.nextInt(50);
JobInfo jobInfo = new JobInfo.Builder(qiscusAccount.getId() + randomValue, componentName)
.setPeriodic(TimeUnit.MINUTES.toMillis(15))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (jobScheduler != null) {
jobScheduler.schedule(jobInfo);
}
}