本文整理汇总了Java中android.app.job.JobInfo.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java JobInfo.Builder方法的具体用法?Java JobInfo.Builder怎么用?Java JobInfo.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.job.JobInfo
的用法示例。
在下文中一共展示了JobInfo.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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();
}
示例3: 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");
}
}
示例4: 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());
}
示例5: 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!");
}
}
示例6: onReceive
import android.app.job.JobInfo; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Log.d(getClass().getName(), "onReceive");
// // Automatically open application
// Intent bootIntent = new Intent(context, MainActivity.class);
// bootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(bootIntent);
// Initiate background job for synchronizing with server content
ComponentName componentName = new ComponentName(context, ContentSynchronizationJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(LiteracyApplication.CONTENT_SYNCRHONIZATION_JOB_ID, componentName);
builder.setPeriodic(1000 * 60 * 30); // Every 30 minutes
JobInfo jobInfo = builder.build();
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(jobInfo);
/*if (StartPrefsHelper.scheduleAfterBoot(context)){
scheduleAuthenticationJobs(context);
} else {
Log.i(getClass().getName(), "Authentication jobs won't be scheduled because the 7 days after first start-up haven't passed yet.");
}*/
scheduleAuthenticationJobs(context);
}
示例7: onClick
import android.app.job.JobInfo; //导入方法依赖的package包/类
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button:
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID,
new ComponentName(this, MyJobService.class));
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresCharging(true);
if (mScheduler.schedule(builder.build())<1) {
Log.e(TAG, "Can't schedule job for some reason. Check your JobInfo parameters");
};
break;
case R.id.cancel_button:
mScheduler.cancel(JOB_ID);
break;
}
}
示例8: getJobInfo
import android.app.job.JobInfo; //导入方法依赖的package包/类
private static JobInfo getJobInfo(boolean requireUnmetered, boolean allowRoaming,
boolean requireCharging) {
JobInfo.Builder builder = new JobInfo.Builder(
JobSchedulerId.BACKGROUND_DOWNLOAD.id(),
new ComponentName("com.totsp.crossword.shortyz",
BackgroundDownloadService.class.getName()));
builder.setPeriodic(TimeUnit.HOURS.toMillis(1))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresCharging(requireCharging)
.setPersisted(true);
if (!requireUnmetered) {
if (allowRoaming) {
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
} else {
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NOT_ROAMING);
}
}
return builder.build();
}
示例9: createJobInfoFromTaskInfo
import android.app.job.JobInfo; //导入方法依赖的package包/类
@VisibleForTesting
static JobInfo createJobInfoFromTaskInfo(Context context, TaskInfo taskInfo) {
PersistableBundle jobExtras = new PersistableBundle();
jobExtras.putString(BACKGROUND_TASK_CLASS_KEY, taskInfo.getBackgroundTaskClass().getName());
PersistableBundle persistableBundle = getTaskExtrasAsPersistableBundle(taskInfo);
jobExtras.putPersistableBundle(BACKGROUND_TASK_EXTRAS_KEY, persistableBundle);
JobInfo.Builder builder =
new JobInfo
.Builder(taskInfo.getTaskId(),
new ComponentName(context, BackgroundTaskJobService.class))
.setExtras(jobExtras)
.setPersisted(taskInfo.isPersisted())
.setRequiresCharging(taskInfo.requiresCharging())
.setRequiredNetworkType(getJobInfoNetworkTypeFromTaskNetworkType(
taskInfo.getRequiredNetworkType()));
if (taskInfo.isPeriodic()) {
builder = getPeriodicJobInfo(builder, taskInfo);
} else {
builder = getOneOffJobInfo(builder, taskInfo);
}
return builder.build();
}
示例10: registerMediaContentJobService
import android.app.job.JobInfo; //导入方法依赖的package包/类
/**
* Method used to register this service on the context.
*
* @param context The application context.
*/
@TargetApi(Build.VERSION_CODES.N)
public void registerMediaContentJobService(Context context) {
if (mSdkInt > Build.VERSION_CODES.N) {
JobInfo.Builder builder = new JobInfo.Builder(MediaContentJobService.JOB_ID, new ComponentName(context, MediaContentJobService.class.getName()));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Images.Media.INTERNAL_CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Video.Media.INTERNAL_CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS));
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
builder.setTriggerContentMaxDelay(1000);
builder.setTriggerContentUpdateDelay(1000);
builder.setRequiresDeviceIdle(false);
logD(TAG, "registerMediaContentJobService");
scheduleMediaContentJobService(context, builder.build());
}
}
示例11: requestImmediateSync1
import android.app.job.JobInfo; //导入方法依赖的package包/类
@Deprecated
public static void requestImmediateSync1(Context context, String inputId, long syncDuration,
ComponentName jobServiceComponent) {
if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) {
throw new IllegalArgumentException("This class does not extend EpgSyncJobService");
}
PersistableBundle persistableBundle = new PersistableBundle();
if (Build.VERSION.SDK_INT >= 22) {
persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
}
persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
persistableBundle.putLong("bundle_key_sync_period", syncDuration);
JobInfo.Builder builder = new JobInfo.Builder(1, jobServiceComponent);
JobInfo jobInfo = builder
.setExtras(persistableBundle)
.setOverrideDeadline(1000)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
scheduleJob(context, jobInfo);
Log.d(TAG, "Single job scheduled");
}
示例12: setUpPeriodicSync
import android.app.job.JobInfo; //导入方法依赖的package包/类
/**
* Initializes a job that will periodically update the app's channels and programs.
*
* @param context Application's context.
* @param inputId Component name for the app's TvInputService. This can be received through an
* Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}.
* @param jobServiceComponent The {@link EpgSyncJobService} component name that will run.
* @param fullSyncPeriod The period between when the job will run a full background sync in
* milliseconds.
* @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync,
* this should be relatively short. For a background sync this should be long.
*/
public static void setUpPeriodicSync(Context context, String inputId,
ComponentName jobServiceComponent, long fullSyncPeriod, long syncDuration) {
if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) {
throw new IllegalArgumentException("This class does not extend EpgSyncJobService");
}
PersistableBundle persistableBundle = new PersistableBundle();
persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration);
JobInfo.Builder builder = new JobInfo.Builder(PERIODIC_SYNC_JOB_ID, jobServiceComponent);
JobInfo jobInfo = builder
.setExtras(persistableBundle)
.setPeriodic(fullSyncPeriod)
.setPersisted(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
scheduleJob(context, jobInfo);
if (DEBUG) {
Log.d(TAG, "Job has been scheduled for every " + fullSyncPeriod + "ms");
}
}
示例13: scheduleJob
import android.app.job.JobInfo; //导入方法依赖的package包/类
/**
* UI onclick listener to schedule a new job.
*/
public void scheduleJob(View v) {
JobInfo.Builder builder = new JobInfo.Builder(kJobId++,mServiceComponent);
String delay = mDelayEditText.getText().toString();
if (delay != null && !TextUtils.isEmpty(delay)) {
builder.setMinimumLatency(Long.valueOf(delay) * 1000);
}
String deadline = mDeadlineEditText.getText().toString();
if (deadline != null && !TextUtils.isEmpty(deadline)) {
builder.setOverrideDeadline(Long.valueOf(deadline) * 1000);
}
boolean requiresUnmetered = mWiFiConnectivityRadioButton.isChecked();
boolean requiresAnyConnectivity = mAnyConnectivityRadioButton
.isChecked();
if (requiresUnmetered) {
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
} else if (requiresAnyConnectivity) {
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
}
builder.setRequiresDeviceIdle(mRequiresIdleCheckbox.isChecked());
builder.setRequiresCharging(mRequiresChargingCheckBox.isChecked());
JobScheduler jobScheduler =
(JobScheduler) getApplication().getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
}
示例14: onStartCommand
import android.app.job.JobInfo; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand(): intent = [" + intent.toUri(0) + "], flags = [" + flags + "], startId = [" + startId + "]");
try {
// 定时检查 WorkService 是否在运行,如果不在运行就把它拉起来
// Android 5.0+ 使用 JobScheduler,效果比 AlarmManager 好
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Log.i(TAG, "开启 JobService 定时");
JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancelAll();
JobInfo.Builder builder = new JobInfo.Builder(1024, new ComponentName(getPackageName(), ScheduleService.class.getName()));
builder.setPeriodic(WAKE_INTERVAL);
builder.setPersisted(true);
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
int schedule = jobScheduler.schedule(builder.build());
if (schedule <= 0) {
Log.w(TAG, "schedule error!");
}
} else {
// Android 4.4- 使用 AlarmManager
Log.i(TAG, "开启 AlarmManager 定时");
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent alarmIntent = new Intent(getApplication(), DaemonService.class);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1024, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pendingIntent);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + WAKE_INTERVAL, WAKE_INTERVAL, pendingIntent);
}
} catch (Exception e) {
Log.e(TAG, "e:", e);
}
// 简单守护开机广播
getPackageManager().setComponentEnabledSetting(
new ComponentName(getPackageName(), DaemonService.class.getName()),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
return super.onStartCommand(intent, flags, startId);
}
示例15: agendarJob
import android.app.job.JobInfo; //导入方法依赖的package包/类
private void agendarJob() {
JobInfo.Builder b = new JobInfo.Builder(JOB_ID, new ComponentName(this, DownloadJobService.class));
PersistableBundle pb=new PersistableBundle();
pb.putBoolean(KEY_DOWNLOAD, true);
b.setExtras(pb);
//criterio de rede
b.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
//b.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE);
//define intervalo de periodicidade
//b.setPeriodic(getPeriod());
//exige (ou nao) que esteja conectado ao carregador
b.setRequiresCharging(false);
//persiste (ou nao) job entre reboots
//se colocar true, tem que solicitar permissao action_boot_completed
b.setPersisted(false);
//exige (ou nao) que dispositivo esteja idle
b.setRequiresDeviceIdle(false);
//backoff criteria (linear ou exponencial)
//b.setBackoffCriteria(1500, JobInfo.BACKOFF_POLICY_EXPONENTIAL);
//periodo de tempo minimo pra rodar
//so pode ser chamado se nao definir setPeriodic...
b.setMinimumLatency(3000);
//mesmo que criterios nao sejam atingidos, define um limite de tempo
//so pode ser chamado se nao definir setPeriodic...
b.setOverrideDeadline(6000);
jobScheduler.schedule(b.build());
}