private void RefreshJobs() { StopJobs(); if (settings != null && settings.EnableAndroidNotification) { CreateAutoJobNotificationChannel(); var jobServ = (JobScheduler)GetSystemService(JobSchedulerService); if (settings.AutoStopWifi.Count > 0 || settings.AutoStartCellur) { JobInfo.Builder jobBuilder = new JobInfo.Builder( TrojanPlusAutoJobService.JobId, new ComponentName(this, Class.FromType(typeof(TrojanPlusAutoJobService)).Name)); jobBuilder.SetRequiredNetworkType(NetworkType.Any); jobBuilder.SetBackoffCriteria(AutoJobServiceBackoffCriteria, BackoffPolicy.Linear); jobBuilder.SetMinimumLatency(AutoJobServiceMinimumLatency); jobBuilder.SetOverrideDeadline(AutoJobServiceMaxLatency); jobBuilder.SetPersisted(true); PersistableBundle bundle = new PersistableBundle(); bundle.PutString("settings", JsonConvert.SerializeObject(settings)); jobBuilder.SetExtras(bundle); var succ = jobServ.Schedule(jobBuilder.Build()); Log.Debug(TAG, "RefreshJobs TrojanPlusAutoJobService " + succ); } } }
private void ShowLater(NotificationRequest notificationRequest) { if (notificationRequest.NotifyTime.HasValue == false) { return; } var triggerTime = NotifyTimeInMilliseconds(notificationRequest.NotifyTime.Value); notificationRequest.NotifyTime = null; var serializedNotification = ObjectSerializer <NotificationRequest> .SerializeObject(notificationRequest); var javaClass = Java.Lang.Class.FromType(typeof(ScheduledNotificationJobService)); var component = new ComponentName(Application.Context, javaClass); // Bundle up parameters var extras = new PersistableBundle(); extras.PutString(NotificationCenter.ExtraReturnNotification, serializedNotification); triggerTime -= NotifyTimeInMilliseconds(DateTime.Now); var builder = new JobInfo.Builder(notificationRequest.NotificationId, component); builder.SetMinimumLatency(triggerTime); // Fire at TriggerTime builder.SetOverrideDeadline(triggerTime + 5000); // Or at least 5 Seconds Later builder.SetExtras(extras); builder.SetPersisted(CheckBootPermission()); //Job will be recreated after Reboot if Permissions are granted var jobInfo = builder.Build(); _jobScheduler.Schedule(jobInfo); }
public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { System.Diagnostics.Debug.WriteLine("Widget OnUpdate"); var me = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name); appWidgetManager.UpdateAppWidget(me, BuildRemoteViews(context, appWidgetIds)); var scheduler = context.GetSystemService(Context.JobSchedulerService) as JobScheduler; var jobName = new ComponentName(context, Java.Lang.Class.FromType(typeof(WidgetJobService)).Name); var jobInfo = new JobInfo.Builder(1, jobName); jobInfo.SetBackoffCriteria(5000, BackoffPolicy.Linear); jobInfo.SetPersisted(true); jobInfo.SetPeriodic(900000); jobInfo.SetRequiredNetworkType(NetworkType.Any); jobInfo.SetRequiresCharging(false); var bundle = new PersistableBundle(); bundle.PutIntArray(WIDGET_BUNDLE, appWidgetIds); jobInfo.SetExtras(bundle); var job = jobInfo.Build(); scheduler.Schedule(job); }
public static void StartJob(Context context) { try { int jobId = 8; Log.Error(TAG, "startJob"); JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); var componentName = new ComponentName(context, Java.Lang.Class.FromType(typeof(WorkJobService))); var builder = new JobInfo.Builder(jobId, componentName).SetPersisted(true); // 小于7.0 if (Build.VERSION.SdkInt < BuildVersionCodes.N) { Log.Error(TAG, "每隔 1s 执行一次 job"); builder.SetPeriodic(1000); } else { // 延迟执行任务 builder.SetMinimumLatency(1000); } int resultCode = jobScheduler.Schedule(builder.Build()); } catch (Exception ex) { Log.Error(TAG, ex.Message); } }
public static void Enqueue( Context context, JobSetting jobSetting ) { JobInfo.Builder jobInfoBuilder = new JobInfo.Builder( JOB_ID, new ComponentName(context, Java.Lang.Class.FromType(typeof(ExposureNotDetectedJob)))) .SetOverrideDeadline(0); if (jobSetting != null) { jobSetting.Apply(jobInfoBuilder); } JobInfo jobInfo = jobInfoBuilder.Build(); JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(JobSchedulerService); int result = jobScheduler.Schedule(jobInfo); if (result == JobScheduler.ResultSuccess) { Logger.D("ExposureNotDetectedJob scheduled"); } else if (result == JobScheduler.ResultFailure) { Logger.D("ExposureNotDetectedJob schedule failed"); } }
private void RunDuringNextWindowIfNotAlreadyScheduled(Context context, Intent intent) { JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); // don't queue another job if there's already one in the pending job queue if (jobScheduler.AllPendingJobs.Any(x => x.Id == RUN_DURING_NEXT_WINDOW)) { Log.Info(TAG, "Another device location update job will not be scheduled because an existing job was found in the queue."); return; } var job = new JobInfo.Builder(RUN_DURING_NEXT_WINDOW, new ComponentName(context, Java.Lang.Class.FromType(typeof(UpdateDeviceLocationJobService)))); var oneMinute = 1 * 60 * 1000; var twoMinutes = 2 * 60 * 1000; var fiveMinutes = 5 * 60 * 1000; job.SetMinimumLatency(oneMinute); // Specify that this job should be delayed by the provided amount of time (in milliseconds) job.SetTriggerContentMaxDelay(twoMinutes); // Set the maximum total delay (in milliseconds) that is allowed //job.SetPeriodic(fiveMinutes); // Specify that this job should recur with the provided interval, not more than once per period. //job.SetPersisted(true); var result = jobScheduler.Schedule(job.Build()); LogScheduleResult(result); }
public override void OnMessageReceived(RemoteMessage message) { var dependencyContainer = AndroidDependencyContainer.Instance; var userIsLoggedIn = dependencyContainer.UserAccessManager.CheckIfLoggedIn(); if (!userIsLoggedIn) { return; } var keyValueStorage = dependencyContainer.KeyValueStorage; if (!shouldScheduleSyncJob(keyValueStorage)) { return; } var jobClass = Java.Lang.Class.FromType(typeof(SyncJobService)); var jobScheduler = (JobScheduler)GetSystemService(JobSchedulerService); var serviceName = new ComponentName(this, jobClass); var jobInfoBuilder = new JobInfo.Builder(SyncJobServiceJobId, serviceName) .SetRequiredNetworkType(NetworkType.Any); if (PieApis.AreAvailable) { jobInfoBuilder = jobInfoBuilder.SetImportantWhileForeground(true); } jobScheduler.Schedule(jobInfoBuilder.Build()); keyValueStorage.SetBool(HasPendingSyncJobServiceScheduledKey, true); keyValueStorage.SetDateTimeOffset(LastSyncJobScheduledAtKey, DateTimeOffset.Now); }
private void ScheduleSyncJob(long accountId) { // JobScheduler was added in API 21 if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { return; } var extras = new PersistableBundle(); extras.PutLong("AccountId", accountId); var builder = new JobInfo.Builder(unchecked ((int)accountId), new ComponentName(this, Java.Lang.Class.FromType(typeof(MySyncService)))) .SetRequiredNetworkType(NetworkType.Any) .SetExtras(extras); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { builder.SetRequiresBatteryNotLow(true); } var jobScheduler = (JobScheduler)this.GetSystemService(Context.JobSchedulerService); jobScheduler.Schedule(builder.Build()); }
public void StartPeriodicBackgroundWorkUsingJobScheduler() { Java.Lang.Class javaClass = Java.Lang.Class.FromType(typeof(GetBitcoinPriceJob)); ComponentName component = new ComponentName(Application.Context, javaClass); int jobId = 2300; JobInfo.Builder builder = new JobInfo.Builder(jobId, component) .SetPeriodic(1000 * 10) // start after every 10 seconds .SetPersisted(true) // job will work after device reboot .SetRequiredNetworkType(NetworkType.Any); // and require internet connection of any type JobInfo jobInfo = builder.Build(); JobScheduler jobScheduler = (JobScheduler)Application.Context.GetSystemService(Context.JobSchedulerService); int result = jobScheduler.Schedule(jobInfo); using (var handler = new Handler(Looper.MainLooper)) { if (result == JobScheduler.ResultSuccess) { Toast.MakeText(Application.Context, "job succesfully scheduled", ToastLength.Short); // The job was scheduled. } else { Toast.MakeText(Application.Context, "job failed to schedule", ToastLength.Short); } } }
/// <summary> /// Schedules the task for execution. /// </summary> public void ScheduleTask(int interval) { if (!Mvx.IoCProvider.CanResolve <ISettingsManager>()) { return; } if (!Mvx.IoCProvider.Resolve <ISettingsManager>().IsBackupAutouploadEnabled) { return; } var builder = new JobInfo.Builder(SYNC_BACK_JOB_ID, new ComponentName( this, Java.Lang.Class.FromType(typeof(SyncBackupJob)))); // convert hours into millisecond builder.SetPeriodic(60 * 60 * 1000 * interval); builder.SetPersisted(true); builder.SetRequiredNetworkType(NetworkType.NotRoaming); builder.SetRequiresDeviceIdle(false); builder.SetRequiresCharging(false); var tm = (JobSchedulerType)GetSystemService(JobSchedulerService); var status = tm.Schedule(builder.Build()); }
public void ScheduleJob(View v) { JobInfo.Builder builder = new JobInfo.Builder(102, new ComponentName(this, Java.Lang.Class.FromType(typeof(JobScedulerSample)))); builder.SetPersisted(true); builder.SetPeriodic(5000); builder.SetRequiredNetworkType(NetworkType.Unmetered); builder.SetRequiresCharging(false); builder.SetRequiresDeviceIdle(false); try { int test = Job_s.Schedule(builder.Build()); if (test == JobScheduler.ResultSuccess) { Console.WriteLine("Job is working"); } else { Console.WriteLine("Job is not working"); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Enqueue( Context context, string token, JobSetting jobSetting ) { PersistableBundle bundle = new PersistableBundle(); bundle.PutString(EXTRA_TOKEN, token); JobInfo.Builder jobInfoBuilder = new JobInfo.Builder( JOB_ID, new ComponentName(context, Java.Lang.Class.FromType(typeof(ExposureDetectedV1Job)))) .SetExtras(bundle) .SetOverrideDeadline(0); if (jobSetting != null) { jobSetting.Apply(jobInfoBuilder); } JobInfo jobInfo = jobInfoBuilder.Build(); JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(JobSchedulerService); int result = jobScheduler.Schedule(jobInfo); if (result == JobScheduler.ResultSuccess) { Logger.D("ExposureDetectedV1Job scheduled"); } else if (result == JobScheduler.ResultFailure) { Logger.D("ExposureDetectedV1Job schedule failed"); } }
public override void OnReceive(Context context, Intent intent) { if (intent.Action.Equals(Telephony.Sms.Intents.SmsReceivedAction)) { SmsMessage[] messages = Telephony.Sms.Intents.GetMessagesFromIntent(intent); IEnumerable <SmsData> smsDataList = ExtractMessages(messages); Intent mailIntent = new Intent(context, typeof(MailPushService)); string json = JsonConvert.SerializeObject(smsDataList); mailIntent.PutExtra("object", json); context.StartService(mailIntent); JobInfo.Builder builder = new JobInfo.Builder(TextPersistenceService.GetNewJobId(), new ComponentName(context, Java.Lang.Class.FromType(typeof(TextPersistenceService)))); PersistableBundle bundle = new PersistableBundle(); bundle.PutString("object", json); builder.SetExtras(bundle); builder.SetMinimumLatency(500); builder.SetOverrideDeadline(1000); JobInfo jobInfo = builder.Build(); JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); jobScheduler.Schedule(jobInfo); } }
private void ShowLater(LocalNotification localNotification) { if (localNotification.NotifyTime.HasValue == false) { return; } var triggerTime = NotifyTimeInMilliseconds(localNotification.NotifyTime.Value); localNotification.NotifyTime = null; var serializedNotification = ObjectSerializer <LocalNotification> .SerializeObject(localNotification); var scheduled = false; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { var javaClass = Java.Lang.Class.FromType(typeof(ScheduledNotificationJobService)); var component = new ComponentName(Application.Context, javaClass); // Bundle up parameters var extras = new PersistableBundle(); extras.PutString(ExtraReturnNotification, serializedNotification); triggerTime -= NotifyTimeInMilliseconds(DateTime.Now); var builder = new JobInfo.Builder(localNotification.NotificationId, component); builder.SetMinimumLatency(triggerTime); // Fire at TriggerTime builder.SetOverrideDeadline(triggerTime + 5000); // Or at least 5 Seconds Later builder.SetExtras(extras); builder.SetPersisted(CheckBootPermission()); //Job will be recreated after Reboot if Permissions are granted var jobInfo = builder.Build(); var result = _jobScheduler.Schedule(jobInfo); scheduled = result == JobScheduler.ResultSuccess; } if (scheduled) { return; } // The job was not scheduled. So use the old implementation var notificationIntent = new Intent(Application.Context, typeof(ScheduledNotificationReceiver)); notificationIntent.SetAction("LocalNotifierIntent" + localNotification.NotificationId); notificationIntent.PutExtra(ExtraReturnNotification, serializedNotification); var pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, notificationIntent, PendingIntentFlags.CancelCurrent); _alarmManager.Set(AlarmType.RtcWakeup, triggerTime, pendingIntent); }
public static JobInfo CreateBackgroundSyncJobInfo(this Context context, long periodicity) { var javaClass = JavaUtils.ToClass <BackgroundSyncJobSchedulerService>(); var component = new ComponentName(context, javaClass); var builder = new JobInfo.Builder(JobServicesConstants.BackgroundSyncJobServiceJobId, component) .SetRequiredNetworkType(NetworkType.Any) .SetPeriodic(periodicity) .SetPersisted(true); var jobInfo = builder.Build(); return(jobInfo); }
public static JobInfo CreateBackgroundSyncJobInfo(this Context context, long periodicity) { var javaClass = Java.Lang.Class.FromType(typeof(BackgroundSyncJobSchedulerService)); var component = new ComponentName(context, javaClass); var builder = new JobInfo.Builder(BackgroundSyncJobSchedulerService.JobId, component) .SetRequiredNetworkType(NetworkType.Any) .SetPeriodic(periodicity) .SetPersisted(true); var jobInfo = builder.Build(); return(jobInfo); }
/// <summary> /// Schedules the task for execution. /// </summary> public void ScheduleTask() { var builder = new JobInfo.Builder(CLEAR_PAYMENT_JOB_ID, new ComponentName( this, Java.Lang.Class.FromType(typeof(ClearPaymentsJob)))); // Execute all 60 Minutes builder.SetPeriodic(60 * 60 * 1000); builder.SetPersisted(true); builder.SetRequiredNetworkType(NetworkType.None); builder.SetRequiresDeviceIdle(false); builder.SetRequiresCharging(false); var tm = (JobSchedulerType)GetSystemService(JobSchedulerService); tm.Schedule(builder.Build()); }
public void SchedulePeriodicWork() { JobScheduler jobScheduler = (JobScheduler)Xamarin.Forms.Forms.Context.GetSystemService(Context.JobSchedulerService); var jobBuilder = new JobInfo.Builder(JobId, new ComponentName(Xamarin.Forms.Forms.Context, Java.Lang.Class.FromType(typeof(ExampleJobService)))); jobBuilder.SetPeriodic(TimeSpan.FromMinutes(3).Milliseconds); jobBuilder.SetOverrideDeadline(TimeSpan.FromMinutes(1).Milliseconds); jobBuilder.SetMinimumLatency(TimeSpan.FromMinutes(1).Milliseconds); jobBuilder.SetTriggerContentMaxDelay(TimeSpan.FromMinutes(1).Milliseconds); var job = jobBuilder.Build(); var result = jobScheduler.Schedule(job); MessagingCenter.Send <XamarinBGServ.App, string>(Xamarin.Forms.Application.Current as XamarinBGServ.App, Messages.ConsoleMessage, result == JobScheduler.ResultSuccess ? "Job scheduled" : "Job scheduling failed"); }
/* UI onclick listener to schedule a job.What this job is is defined in * TestJobService#scheduleJob(). */ public void ScheduleJob() { var builder = new JobInfo.Builder(kJobId++, serviceComponent); //builder.SetMinimumLatency(periodInMins * 60 * 1000); builder.SetPeriodic((long)periodInMins * 60 * 1000); //builder.SetPersisted(true); //The service can wait up to an aditional 30 seconds before it must execute builder.SetRequiresDeviceIdle(false); builder.SetRequiresCharging(false); notificationService = new LocalNotificationJobService(mainContext); notificationService.ScheduleJob(builder.Build()); }
public void ScheduleTask() { var builder = new JobInfo.Builder(RECURRING_PAYMENT_JOB_ID, new ComponentName( this, Java.Lang.Class.FromType(typeof(SyncBackupJob)))); // Execute all 30 Minutes builder.SetPeriodic(30 * 60 * 1000); builder.SetPersisted(true); builder.SetRequiredNetworkType(NetworkType.None); builder.SetRequiresDeviceIdle(false); builder.SetRequiresCharging(false); var tm = (JobSchedulerType)GetSystemService(Context.JobSchedulerService); var status = tm.Schedule(builder.Build()); }
public void ScheduleJob() { try{ Intent intent = new Intent(); String packageName = Application.Context.PackageName; PowerManager pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService); if (pm.IsIgnoringBatteryOptimizations(packageName)) { intent.SetAction(Android.Provider.Settings.ActionIgnoreBatteryOptimizationSettings); } else { intent.SetAction(Android.Provider.Settings.ActionRequestIgnoreBatteryOptimizations); intent.SetData(Android.Net.Uri.Parse("package:" + packageName)); } intent.AddFlags(ActivityFlags.NewTask); Application.Context.StartActivity(intent); } catch (Exception ex) { Console.WriteLine(ex); } var tm = (JobSchedulerType)GetSystemService(Context.JobSchedulerService); var jobs = tm.AllPendingJobs; tm.CancelAll(); JobInfo.Builder builder = this.CreateJobInfoBuilder() .SetPersisted(true) .SetRequiresDeviceIdle(false) .SetPeriodic(Config.UpdateTimeInterval * 60000) .SetRequiredNetworkType(NetworkType.Any); int result = jobScheduler.Schedule(builder.Build()); if (result == JobScheduler.ResultSuccess) { Log.Debug(TAG, "Job started!"); } else { Log.Warn(TAG, "Problem starting the job " + result); } }
// todo p238-239 schedule location job service public void StartTracking() { var javaClass = Java.Lang.Class.FromType(typeof(LocationJobService)); var componentName = new ComponentName(Application.Context, javaClass); var jobBuilder = new JobInfo.Builder(1, componentName); jobBuilder.SetOverrideDeadline(1000); jobBuilder.SetPersisted(true); jobBuilder.SetRequiresDeviceIdle(false); jobBuilder.SetRequiresBatteryNotLow(true); var jobInfo = jobBuilder.Build(); var jobScheduler = (JobScheduler)Application.Context.GetSystemService(Context.JobSchedulerService); jobScheduler.Schedule(jobInfo); }
/// <summary> /// Schedules the task for execution. /// </summary> public void ScheduleTask() { var builder = new JobInfo.Builder(RECURRING_PAYMENT_JOB_ID, new ComponentName( this, Class.FromType(typeof(RecurringPaymentJob)))); // Execute all 60 Minutes builder.SetPeriodic(JOB_INTERVAL); builder.SetPersisted(true); builder.SetRequiredNetworkType(NetworkType.None); builder.SetRequiresDeviceIdle(false); builder.SetRequiresCharging(false); var tm = (JobSchedulerType)GetSystemService(JobSchedulerService); tm.Schedule(builder.Build()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); Button b = FindViewById <Button>(Resource.Id.button); b.Click += delegate { ComponentName cn = new ComponentName(this, Class.FromType(typeof(MyJobService))); JobInfo.Builder builder = new JobInfo.Builder(123, cn); long millis = 5 * 60 * 1000; builder.SetPeriodic(millis); JobScheduler js = (JobScheduler)GetSystemService(Context.JobSchedulerService); js.Schedule(builder.Build()); }; }
public void StartJob() { try { //Supports After APi level 21 only if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { return; } ComponentName serviceComponent = new ComponentName(ActivtyContext, Java.Lang.Class.FromType(typeof(DataLoaderJobService))); if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { Jobbuilder = new JobInfo.Builder(Jobid, serviceComponent); Jobbuilder.SetMinimumLatency(4000); Jobbuilder.SetRequiredNetworkType(NetworkType.Any); Jobbuilder.SetRequiresCharging(false); Jobbuilder.SetOverrideDeadline(4000); Jobbuilder.SetBackoffCriteria(3000, BackoffPolicy.Linear); Jobbuilder.SetPersisted(true); } else { Jobbuilder = new JobInfo.Builder(Jobid, serviceComponent); Jobbuilder.SetPeriodic(2000); Jobbuilder.SetPersisted(true); Jobbuilder.SetRequiredNetworkType(NetworkType.Any); Jobbuilder.SetRequiresCharging(false); } Jobscheduler = (JobScheduler)ActivtyContext.GetSystemService(Context.JobSchedulerService); int result = Jobscheduler.Schedule(Jobbuilder.Build()); if (result == JobScheduler.ResultSuccess) { } } catch (Exception e) { Crashes.TrackError(e); } }
private void StartService() { if (mJobScheduler != null) { // Thread.CurrentThread.CurrentCulture = new CultureInfo("bg-BG"); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("bg-BG"); mJobScheduler = (JobScheduler)GetSystemService(Context.JobSchedulerService); JobScheduler = new ComponentName(this, Java.Lang.Class.FromType(typeof(MyJobService))); JobInfo.Builder builder = new JobInfo.Builder(kJobId++, JobScheduler); builder.SetRequiredNetworkType(NetworkType.Any); builder.SetPeriodic(3600000); // 2400000 40 min, 7200000, ////////////3600000 // builder.SetPeriodic(900000); // 2400000 40 min, // 1500 20 000 - 2s // 25 min builder.SetPersisted(true); mJobScheduler.Schedule(builder.Build()); } }
private void Weatherupdatefrequency_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) { long interval_minutes = int.Parse(Resources.GetStringArray(Resource.Array.listvaluesweatherupdatefrequency)[e.Position]); JobInfo.Builder jobBuilder = new JobInfo.Builder(56114281, new ComponentName(Application.Context, Java.Lang.Class.FromType(typeof(GrabWeatherJob)))); jobBuilder.SetPersisted(true); jobBuilder.SetPeriodic(1000 * 60 * interval_minutes); jobBuilder.SetRequiredNetworkType(Android.App.Job.NetworkType.Unmetered); JobScheduler jobScheduler = (JobScheduler)Application.Context.GetSystemService(Context.JobSchedulerService); int result = jobScheduler.Schedule(jobBuilder.Build()); if (result == JobScheduler.ResultSuccess) { Log.Info("LiveDisplay", "Job Result Sucess"); } else { Log.Info("LiveDisplay", "Job Result Not Sucess"); } }
public static void StartJob(Context context) { Log.Error(TAG, "startJob"); JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); JobInfo.Builder builder = new JobInfo.Builder(8, new ComponentName(context.PackageName, typeof(WorkJobService).Name)).SetPersisted(true); // 小于7.0 if (Build.VERSION.SdkInt < BuildVersionCodes.N) { builder.SetPeriodic(1000); } else { builder.SetMinimumLatency(1000); } jobScheduler.Schedule(builder.Build()); }
public static void ScheduleJob(Context context) { ComponentName serviceComponent = new ComponentName(context, Java.Lang.Class.FromType(typeof(WorkerService))); JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent) .SetPersisted(true) .SetPeriodic(AlarmManager.IntervalDay); //A day. //Configurable? JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); JobInfo jobInfo = builder.Build(); int result = jobScheduler.Schedule(jobInfo); if (result == JobScheduler.ResultSuccess) { Log.Info("Astropix", "Job Result Sucess"); } else { Log.Info("Astropix", "Job Result Not Sucess"); } }
private void RunImmediately(Context context, Intent intent) { JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(Context.JobSchedulerService); // don't queue another job if there's already one in the pending pjob queue if (jobScheduler.AllPendingJobs.Any(x => x.Id == RUN_IMMEDIATELY)) { Log.Info(TAG, "Another device location update job will not run because an existing job was found in the queue."); return; } var job = new JobInfo.Builder(RUN_IMMEDIATELY, new ComponentName(context, Java.Lang.Class.FromType(typeof(UpdateDeviceLocationJobService)))); job.SetMinimumLatency(100); job.SetTriggerContentMaxDelay(1000); var result = jobScheduler.Schedule(job.Build()); LogScheduleResult(result); }
public void ScheduleJob (View v) { if (!EnsureTestService ()) { return; } var builder = new JobInfo.Builder (kJobId++, serviceComponent); var delay = delayEditText.Text; if (delay != null && !TextUtils.IsEmpty (delay)) { builder.SetMinimumLatency (long.Parse (delay) * 1000); } var deadline = deadlineEditText.Text; if (deadline != null && !TextUtils.IsEmpty (deadline)) { builder.SetOverrideDeadline (long.Parse (deadline) * 1000); } bool requiresUnmetered = wiFiConnectivityRadioButton.Checked; bool requiresAnyConnectivity = anyConnectivityRadioButton.Checked; if (requiresUnmetered) { builder.SetRequiredNetworkCapabilities (NetworkTypeValue.Unmetered); } else if (requiresAnyConnectivity) { builder.SetRequiredNetworkCapabilities (NetworkTypeValue.Any); } builder.SetRequiresDeviceIdle (requiresIdleCheckbox.Checked); builder.SetRequiresCharging (requiresChargingCheckBox.Checked); testService.ScheduleJob (builder.Build ()); }