protected override void ScheduleNative(JobInfo jobInfo) { this.CancelNative(jobInfo); var newJobId = this.settings.IncrementValue("JobId"); var builder = new JobBuilder( newJobId, new ComponentName( context.AppContext, Class.FromType(typeof(ShinyJobService)) ) ) .SetShinyIdentifier(jobInfo.Identifier) .SetPersisted(true) .SetRequiresCharging(jobInfo.DeviceCharging); if (jobInfo.PeriodicTime != null) { if (jobInfo.PeriodicTime < TimeSpan.FromMinutes(15)) { throw new ArgumentException("You cannot schedule periodic jobs faster than 15 minutes"); } builder.SetPeriodic(Convert.ToInt64(System.Math.Round(jobInfo.PeriodicTime.Value.TotalMilliseconds, 0))); } if (jobInfo.BatteryNotLow) { if (this.context.IsMinApiLevel(26)) { builder.SetRequiresBatteryNotLow(jobInfo.BatteryNotLow); } else { Log.Write(nameof(JobManager), "BatteryNotLow criteria is only supported on API 26+"); } } if (jobInfo.RequiredInternetAccess != InternetAccess.None) { var networkType = jobInfo.RequiredInternetAccess == InternetAccess.Unmetered ? NetworkType.Unmetered : NetworkType.Any; builder.SetRequiredNetworkType(networkType); } var nativeJob = builder.Build(); this.context.Native().Schedule(nativeJob); }
public static void StartJobService() { var sch = NativeScheduler(); if (!sch.AllPendingJobs.Any(x => x.Id == CrossJobs.AndroidJobId)) { var job = new Android.App.Job.JobInfo.Builder( CrossJobs.AndroidJobId, new ComponentName( Application.Context, Class.FromType(typeof(PluginJobService)) ) ) .SetPeriodic(Convert.ToInt64(CrossJobs.PeriodicRunTime.TotalMilliseconds)) .SetPersisted(true) .Build(); sch.Schedule(job); } }
public static void StartJobService(this AndroidContext context) { var sch = context.NativeScheduler(); if (!sch.AllPendingJobs.Any(x => x.Id == ANDROID_JOB_ID)) { var job = new Android.App.Job.JobInfo.Builder( ANDROID_JOB_ID, new ComponentName( context.AppContext, Class.FromType(typeof(ShinyJobService)) ) ) .SetPeriodic(Convert.ToInt64(PeriodicJobInterval.TotalMilliseconds)) .SetPersisted(true) .Build(); sch.Schedule(job); } }
void StartJobService() { var sch = this.NativeScheduler(); if (!sch.AllPendingJobs.Any(x => x.Id == AndroidJobId)) { var job = new Android.App.Job.JobInfo.Builder( AndroidJobId, new ComponentName( this.context.AppContext, Class.FromType(typeof(ShinyJobService)) ) ) .SetPeriodic(Convert.ToInt64(PeriodicRunTime.TotalMilliseconds)) .SetPersisted(true) .Build(); sch.Schedule(job); } }