微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.app.job.JobInfo的实例源码

项目:androidbeginners-Lesson3    文件MainActivity.java   
@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);

}
项目:Udhari    文件SettingsActivity.java   
@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);
        }
    }
}
项目:nifi-android-s2s    文件SitetoSiteJobServiceTest.java   
@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();
}
项目:androidtv-sample    文件SyncUtils.java   
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);
}
项目:androidtv-sample    文件RichBootReceiver.java   
@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);
            }
        }
    }
}
项目:leanback-homescreen-channels    文件AddWatchNextService.java   
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,AddWatchNextService.class))
            .setMinimumLatency(0)
            .setExtras(bundle)
            .build());
}
项目:VirtualHook    文件VJobSchedulerService.java   
@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);
}
项目:QuickPeriodicJobScheduler    文件InstrumentedTests.java   
@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);
}
项目:TPlayer    文件VJobSchedulerService.java   
@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,mJobProxyComponent);
    return mScheduler.schedule(job);
}
项目:SimpleRSSReader    文件PeriodicJob.java   
@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");
    }
}
项目:container    文件VJobSchedulerService.java   
@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,mJobProxyComponent);
    return mScheduler.schedule(job);
}
项目:MaterialFBook    文件Scheduler.java   
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");
    }
}
项目:intra42    文件NotificationsJobService.java   
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());
    }
项目:Latestdiscounts    文件PollJobService.java   
@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,PollJobService.class))
                .setrequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
                .setPeriodic(pollInterval)
                .setPersisted(true)
                .build();
        scheduler.schedule(jobInfo);
    }
}
项目:Asynchronous-Android-Programming    文件JobListRecyclerAdapter.java   
@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();
        }
    });
}
项目:stockhawk    文件QuoteSyncJob.java   
private static void schedulePeriodic(Context context) {
    Timber.d("Scheduling a periodic task");

    JobInfo.Builder builder = new JobInfo.Builder(
            PERIODIC_ID,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!");
    }

}
项目:qiscus-sdk-android    文件QiscusSyncJobService.java   
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);
    }

}
项目:mobile-messaging-sdk-android    文件MobileMessagingJobService.java   
private static void registerForNetworkAvailability(Context context) {
    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
    if (jobScheduler == null) {
        return;
    }

    int scheduleId = getScheduleId(context,ON_NETWORK_AVAILABLE_JOB_ID);

    jobScheduler.cancel(scheduleId);

    int r = jobScheduler.schedule(new JobInfo.Builder(scheduleId,MobileMessagingJobService.class))
            .setrequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build());
    if (r == JobScheduler.RESULT_SUCCESS) {
        MobileMessagingLogger.d(TAG,"Registered job for connectivity updates");
    } else {
        MobileMessagingLogger.e(TAG,"Failed to register job for connectivity updates");
    }
}
项目:authentication    文件BootReceiver.java   
@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);
    }
项目:materialistic    文件WidgetHelper.java   
private void scheduleUpdate(int appWidgetId) {
    String frequency = getConfig(appWidgetId,R.string.pref_widget_frequency);
    long frequencyHourMillis = DateUtils.HOUR_IN_MILLIS * (TextUtils.isEmpty(frequency) ?
            DEFAULT_FREQUENCY_HOUR : Integer.valueOf(frequency));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getJobScheduler().schedule(new JobInfo.Builder(appWidgetId,new ComponentName(mContext.getPackageName(),WidgetRefreshJobService.class.getName()))
                .setrequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .setPeriodic(frequencyHourMillis)
                .build());
    } else {
        mAlarmManager.setInexactRepeating(AlarmManager.RTC,System.currentTimeMillis() + frequencyHourMillis,frequencyHourMillis,createRefreshPendingIntent(appWidgetId));
    }

}
项目:materialistic    文件ItemSyncJobServiceTest.java   
@Test
public void testScheduledJob() {
    PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application)
            .edit()
            .putBoolean(RuntimeEnvironment.application.getString(R.string.pref_saved_item_sync),true)
            .apply();
    shadowOf((ConnectivityManager) RuntimeEnvironment.application
            .getSystemService(Context.CONNECTIVITY_SERVICE))
            .setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null,ConnectivityManager.TYPE_WIFI,true,true));
    new SyncScheduler().scheduleSync(RuntimeEnvironment.application,"1");
    List<JobInfo> pendingJobs = shadowOf((JobScheduler) RuntimeEnvironment.application
            .getSystemService(Context.JOB_SCHEDULER_SERVICE)).getAllPendingJobs();
    assertthat(pendingJobs).isNotEmpty();
    JobInfo actual = pendingJobs.get(0);
    assertthat(actual.getService().getClassName())
            .isEqualTo(ItemSyncJobService.class.getName());
}
项目:geohashdroid    文件AlarmService.java   
private void waitForNetwork() {
    // SDK check!  We'll go with JobScheduler if we can.
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // JobScheduler time!  It's fancier!
        JobScheduler js = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo job = new JobInfo.Builder(
                ALARM_CONNECTIVITY_JOB,new ComponentName(this,AlarmServiceJobService.class))
                .setrequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        js.schedule(job);
    } else {
        // Otherwise,just use the ol' package component.
        AndroidUtil.setPackageComponentEnabled(this,NetworkReceiver.class,true);
    }
}
项目:geohashdroid    文件WikiService.java   
private void showWaitingForConnectionNotification() {
    Notification.Builder builder = getFreshNotificationBuilder()
            .setongoing(true)
            .setContentTitle(getString(R.string.wiki_notification_waiting_for_connection_title))
            .setContentText(getString(R.string.wiki_notification_waiting_for_connection_content))
            .setSmallIcon(R.drawable.ic_stat_navigation_more_horiz)
            .setContentIntent(getBasicCommandIntent(QueueService.COMMAND_RESUME));

    mnotificationmanager.notify(R.id.wiki_waiting_notification,builder.build());

    // If we have JobScheduler (SDK 21 or higher),use that.  Otherwise,go
    // with the old ConnectivityListener style.
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler js = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo job = new JobInfo.Builder(
                WIKI_CONNECTIVITY_JOB,WikiServiceJobService.class))
                .setrequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        js.schedule(job);
    } else {
        // Make sure the connectivity listener's waiting for a connection.
        AndroidUtil.setPackageComponentEnabled(this,WikiServiceConnectivityListener.class,true);
    }
}
项目:lecture_examples    文件MainActivity.java   
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.button:

            JobInfo.Builder builder = new JobInfo.Builder(JOB_ID,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;
    }
}
项目:shortyz    文件BackgroundDownloadService.java   
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();
}
项目:shortyz    文件BackgroundDownloadService.java   
private static void scheduleJob(Context context) {
    JobScheduler scheduler =
            (JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    JobInfo info = getJobInfo(
            preferences.getBoolean("backgroundDownloadRequireUnmetered",true),preferences.getBoolean("backgroundDownloadAllowRoaming",false),preferences.getBoolean("backgroundDownloadRequireCharging",false));


    LOGGER.info("Scheduling background download job: " + info);

    int result = scheduler.schedule(info);

    if (result == JobScheduler.RESULT_SUCCESS) {
        LOGGER.info("Successfully scheduled background downloads");
    } else {
        LOGGER.log(Level.WARNING,"Unable to schedule background downloads");
    }
}
项目:android-job    文件JobProxy21.java   
@Override
public void plantOneOff(JobRequest request) {
    long startMs = Common.getStartMs(request);
    long endMs = Common.getEndMs(request,true);

    JobInfo jobInfo = createBuilderOneOff(createBaseBuilder(request,startMs,endMs).build();
    int scheduleResult = schedule(jobInfo);

    if (scheduleResult == ERROR_BOOT_PERMISSION) {
        jobInfo = createBuilderOneOff(createBaseBuilder(request,endMs).build();
        scheduleResult = schedule(jobInfo);
    }

    mCat.d("Schedule one-off jobInfo %s,%s,start %s,end %s (from Now),reschedule count %d",scheduleResultToString(scheduleResult),request,JobUtil.timetoString(startMs),JobUtil.timetoString(endMs),Common.getRescheduleCount(request));
}
项目:android-job    文件JobProxy21.java   
@Override
public void plantPeriodic(JobRequest request) {
    long intervalMs = request.getIntervalMs();
    long flexms = request.getFlexms();

    JobInfo jobInfo = createBuilderPeriodic(createBaseBuilder(request,intervalMs,flexms).build();
    int scheduleResult = schedule(jobInfo);

    if (scheduleResult == ERROR_BOOT_PERMISSION) {
        jobInfo = createBuilderPeriodic(createBaseBuilder(request,flexms).build();
        scheduleResult = schedule(jobInfo);
    }

    mCat.d("Schedule periodic jobInfo %s,interval %s,flex %s",JobUtil.timetoString(intervalMs),JobUtil.timetoString(flexms));
}
项目:android-job    文件JobProxy21.java   
@Override
public void plantPeriodicFlexSupport(JobRequest request) {
    long startMs = Common.getStartMsSupportFlex(request);
    long endMs = Common.getEndMsSupportFlex(request);

    JobInfo jobInfo = createBuilderOneOff(createBaseBuilder(request,endMs).build();
        scheduleResult = schedule(jobInfo);
    }

    mCat.d("Schedule periodic (flex support) jobInfo %s,end %s,JobUtil.timetoString(request.getFlexms()));
}
项目:android-job    文件JobProxy21.java   
@Override
public boolean isPlatformJobScheduled(JobRequest request) {
    List<JobInfo> pendingJobs;
    try {
        pendingJobs = getJobScheduler().getAllPendingJobs();
    } catch (Exception e) {
        // it's possible that this throws an exception,see https://gist.github.com/vRallev/a59947dd3932d2642641
        mCat.e(e);
        return false;
    }

    //noinspection ConstantConditions
    if (pendingJobs == null || pendingJobs.isEmpty()) {
        return false;
    }

    for (JobInfo info : pendingJobs) {
        if (isJobInfoScheduled(info,request)) {
            return true;
        }
    }

    return false;
}
项目:android-job    文件JobProxy21.java   
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) {
    switch (networkType) {
        case ANY:
            return JobInfo.NETWORK_TYPE_NONE;
        case CONNECTED:
            return JobInfo.NETWORK_TYPE_ANY;
        case UNMETERED:
            return JobInfo.NETWORK_TYPE_UNMETERED;
        case NOT_ROAMING:
            return JobInfo.NETWORK_TYPE_UNMETERED; // use unmetered here,is overwritten in v24
        case METERED:
            return JobInfo.NETWORK_TYPE_ANY; // use any here as fallback
        default:
            throw new IllegalStateException("not implemented");
    }
}
项目:365browser    文件BackgroundTaskSchedulerJobService.java   
@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(),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();
}
项目:365browser    文件BackgroundTaskSchedulerJobService.java   
@Override
public boolean schedule(Context context,TaskInfo taskInfo) {
    ThreadUtils.assertOnUiThread();
    if (!BackgroundTaskScheduler.hasParameterlesspublicConstructor(
                taskInfo.getBackgroundTaskClass())) {
        Log.e(TAG,"BackgroundTask " + taskInfo.getBackgroundTaskClass()
                        + " has no parameterless public constructor.");
        return false;
    }

    JobInfo jobInfo = createJobInfoFromTaskInfo(context,taskInfo);

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

    if (taskInfo.shouldUpdateCurrent()) {
        jobScheduler.cancel(taskInfo.getTaskId());
    }

    int result = jobScheduler.schedule(jobInfo);
    return result == JobScheduler.RESULT_SUCCESS;
}
项目:dscautorename    文件DSCApplication.java   
/**
 * 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,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());
    }
}
项目:CumulusTV    文件CumulusJobService.java   
@Deprecated
public static void requestImmediateSync1(Context context,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");
}
项目:NasaPic    文件PeriodicWallpaperChangeService.java   
public static void setupIfNeededPeriodicWallpaperChange(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Resources res = context.getResources();
        JobScheduler scheduler = (JobScheduler) context
                .getSystemService(Context.JOB_SCHEDULER_SERVICE);

        if (scheduler.getAllPendingJobs().size() == 0) {
            ComponentName serviceEndpoint = new ComponentName(context,PeriodicWallpaperChangeService.class);
            JobInfo wallpaperChangeJob = new JobInfo.Builder(
                    PeriodicWallpaperChangeService.JOB_ID,serviceEndpoint)
                    .setRequiresCharging(false)
                    .setrequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                    .setPersisted(true)
                    .setRequiresdeviceidle(true)
                    .setPeriodic(PERIOD_IN_HOURS * 60 * 60 * 1000)
                    .build();

            scheduler.schedule(wallpaperChangeJob);
            String scheduledMessage = res.getString(R.string.periodic_change_scheduled);
            Toast.makeText(context,scheduledMessage,Toast.LENGTH_SHORT).show();
        }
    }
}
项目:androidtv-sample-inputs    文件RichBootReceiver.java   
@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,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);
            }
        }
    }
}
项目:androidtv-sample-inputs    文件EpgSyncJobService.java   
/**
 * 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,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");
    }
}
项目:muzei    文件TaskQueueService.java   
private void scheduleRetryArtworkDownload() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(new JobInfo.Builder(LOAD_ARTWORK_JOB_ID,DownloadArtworkJobService.class))
                .setrequiredNetworkType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                        ? JobInfo.NETWORK_TYPE_NOT_ROAMING
                        : JobInfo.NETWORK_TYPE_ANY)
                .build());
    } else {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        int reloadAttempt = sp.getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT,0);
        sp.edit().putInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT,reloadAttempt + 1).apply();
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        long retryTimeMillis = SystemClock.elapsedRealtime() + (1 << reloadAttempt) * 2000;
        am.set(AlarmManager.ELAPSED_REALTIME,retryTimeMillis,TaskQueueService.getArtworkDownloadRetryPendingIntent(this));
    }
}
项目:muzei    文件TaskQueueService.java   
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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。