Example #1
0
        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);
                }
            }
        }
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
        /// <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 #4
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 #5
0
        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);
        }
        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);
        }
Example #7
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());
        }
        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 #9
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());
        }
        // 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);
        }
        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");
            }
        }
Example #14
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());
        }
Example #15
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 #16
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();
            }
        }