Example #1
0
        /// <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());
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        /// <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());
        }
Example #5
0
        /* 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());
        }
Example #7
0
        /// <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());
        }
        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);
            }
        }
Example #9
0
        /// <summary>
        ///     Schedules the task for execution.
        /// </summary>
        public void ScheduleTask(int interval)
        {
            if (!ServiceLocator.Current.GetInstance <ISettingsFacade>().IsBackupAutouploadEnabled)
            {
                return;
            }

            var builder = new JobInfo.Builder(SYNC_BACK_JOB_ID,
                                              new ComponentName(
                                                  this, Class.FromType(typeof(SyncBackupJob))));

            // convert hours into millisecond
            builder.SetPeriodic(JOB_INTERVAL * interval);
            builder.SetPersisted(true);
            builder.SetRequiredNetworkType(NetworkType.NotRoaming);
            builder.SetRequiresDeviceIdle(false);
            builder.SetRequiresCharging(false);

            var tm = (JobSchedulerType)GetSystemService(JobSchedulerService);

            tm.Schedule(builder.Build());
        }
        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.SetRequiredNetworkType(NetworkType.Unmetered);
            }
            else if (requiresAnyConnectivity)
            {
                builder.SetRequiredNetworkType(NetworkType.Any);
            }

            builder.SetRequiresDeviceIdle(requiresIdleCheckbox.Checked);
            builder.SetRequiresCharging(requiresChargingCheckBox.Checked);

            testService.ScheduleJob(builder.Build());
        }
Example #11
0
        public void ScheduleTask()
        {
            var settingsManager = Mvx.Resolve <ISettingsManager>();

            if (!settingsManager.IsBackupAutouploadEnabled)
            {
                return;
            }

            var builder = new JobInfo.Builder(SYNC_BACK_JOB_ID,
                                              new ComponentName(
                                                  this, Java.Lang.Class.FromType(typeof(SyncBackupJob))));

            // Execute all 30 Minutes
            builder.SetPeriodic(60 * 60 * 1000 * settingsManager.BackupSyncRecurrence);
            builder.SetPersisted(true);
            builder.SetRequiredNetworkType(NetworkType.NotRoaming);
            builder.SetRequiresDeviceIdle(false);
            builder.SetRequiresCharging(false);

            var tm     = (JobSchedulerType)GetSystemService(JobSchedulerService);
            var status = tm.Schedule(builder.Build());
        }
Example #12
0
        private void StartJob(Context context, Intent implicitIntent)
        {
            try
            {
                this.mJobScheduler = (JobScheduler)this.GetSystemService(Context.JobSchedulerService);
                this.mJobScheduler.Cancel(this.jobId);

                if (this.jobId != -1)
                {
                    this.mJobScheduler.Cancel(this.jobId);
                }

                jobId = 100;

                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    ComponentName component = null;

                    PackageManager pm = context.PackageManager;
                    //查出所有的能匹配这个隐式意图的服务列表
                    var resolveInfo = pm.QueryIntentServices(implicitIntent, 0);
                    if (resolveInfo != null || resolveInfo.Count == 1)
                    {
                        ResolveInfo serviceInfo = resolveInfo[0];
                        //取出包名
                        string packageName = serviceInfo.ServiceInfo.PackageName;
                        //取出服务名
                        string className = serviceInfo.ServiceInfo.Name;
                        //用包名和服务名来创建一个ComponentName对象
                        component = new ComponentName(packageName, className);
                    }

                    if (component != null)
                    {
                        var builder = new JobInfo.Builder(this.jobId, component);

                        //24
                        if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
                        {
                            //7.0以上延迟3s执行
                            builder.SetMinimumLatency(30000L);     ////执行的最小延迟时间
                            builder.SetOverrideDeadline(30000L);   ////执行的最长延时时间
                            builder.SetMinimumLatency(30000L);
                            builder.SetBackoffCriteria(30000L, 0); //线性重试方案
                        }
                        else
                        {
                            //每隔3s执行一次job
                            builder.SetPeriodic(30000L);
                        }

                        builder.SetRequiredNetworkType(NetworkType.Any);

                        // 当插入充电器,执行该任务
                        builder.SetRequiresCharging(true);
                        builder.SetPersisted(true);

                        this.mJobScheduler.Schedule(builder.Build());
                    }
                }
            }
            catch (Java.Lang.Exception ex)
            {
                ex.PrintStackTrace();
            }
        }
Example #13
0
		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 ());
		}