本文整理匯總了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());
}