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


Java JobInfo.Builder方法代码示例

本文整理汇总了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);
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:20,代码来源:SyncUtils.java

示例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();
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:19,代码来源:SiteToSiteJobServiceTest.java

示例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");
    }
}
 
开发者ID:ZeeRooo,项目名称:MaterialFBook,代码行数:27,代码来源:Scheduler.java

示例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());
    }
 
开发者ID:pvarry,项目名称:intra42,代码行数:17,代码来源:NotificationsJobService.java

示例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!");
    }

}
 
开发者ID:jkozh,项目名称:stockhawk,代码行数:24,代码来源:QuoteSyncJob.java

示例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);
    }
 
开发者ID:elimu-ai,项目名称:authentication,代码行数:26,代码来源:BootReceiver.java

示例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;
    }
}
 
开发者ID:abdulla-alali,项目名称:lecture_examples,代码行数:23,代码来源:MainActivity.java

示例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();
}
 
开发者ID:kebernet,项目名称:shortyz,代码行数:23,代码来源:BackgroundDownloadService.java

示例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();
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:27,代码来源:BackgroundTaskSchedulerJobService.java

示例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());
	}
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:22,代码来源:DSCApplication.java

示例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");
}
 
开发者ID:Fleker,项目名称:CumulusTV,代码行数:23,代码来源:CumulusJobService.java

示例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");
    }
}
 
开发者ID:googlesamples,项目名称:androidtv-sample-inputs,代码行数:33,代码来源:EpgSyncJobService.java

示例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());
}
 
开发者ID:vogellacompany,项目名称:codeexamples-android,代码行数:29,代码来源:MainActivity.java

示例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);
}
 
开发者ID:isuperqiang,项目名称:AndroidKeepLivePractice,代码行数:38,代码来源:DaemonService.java

示例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());
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:37,代码来源:JobSchedulerActivity.java


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