Пример #1
0
        public override bool OnStartJob(JobParameters parm)
        {
            Log.Debug(TAG, "OnStartJob");

            jobParam = parm;
            settings = JsonConvert.DeserializeObject <SettingsModel>(jobParam.Extras.GetString("settings"));

            ConnectivityManager connManager = (ConnectivityManager)GetSystemService(ConnectivityService);

            if (connManager != null)
            {
                var builder = new NetworkRequest.Builder();
                builder.AddTransportType(TransportType.Wifi);
                builder.AddTransportType(TransportType.WifiAware);
                builder.AddTransportType(TransportType.Cellular);

                connectivityCallback = new ConnectivitiyCallback(this);
                connManager.RegisterNetworkCallback(builder.Build(), connectivityCallback);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        private void Start()
        {
            var settings = _settingsService.GetSettings();

            StartLocationUpdates();

            var builder = new NetworkRequest.Builder();

            builder.AddTransportType(TransportType.Wifi);
            var networkRequest = builder.Build();

            _customNetworkCallback = new CustomNetworkCallback((WifiManager)GetSystemService(WifiService), StartLocationUpdates, StopLocationUpdates);
            ConnectivityManager.RegisterNetworkCallback(networkRequest, _customNetworkCallback);

            if (settings.IsEmailSendingEnabled)
            {
                var request = PeriodicWorkRequest
                              .Builder
                              .From <UploaderWorker>(TimeSpan.FromMinutes(settings.EmailSendingInterval))
                              //.SetBackoffCriteria(BackoffPolicy.Linear, TimeSpan.FromMinutes(5))
                              .SetConstraints(GetConstraints(settings))
                              .Build();

                WorkManager.Instance.EnqueueUniquePeriodicWork("GpsTrackerUploaderWorker", ExistingPeriodicWorkPolicy.Keep, request); // TODO: ExistingPeriodicWorkPolicy.Replace?
            }

            IsStarted = true;
        }
Пример #3
0
        /// <summary>
        /// Forces the cellular over wifi.
        /// </summary>
        public void ForceCellularOverWifi()
        {
            ConnectivityManager connection_manager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);

            NetworkRequest.Builder request = new NetworkRequest.Builder();
            request.AddTransportType(TransportType.Cellular);

            connection_manager.RegisterNetworkCallback(request.Build(), new CustomNetworkAvailableCallBack());
        }
Пример #4
0
        public override void OnCreate()
        {
            base.OnCreate();

#if !DEBUG
            var jobScheduler = (JobScheduler)GetSystemService(JobSchedulerService);

            // Sync

            var jobBuilder = Utilities.CreateJobBuilderUsingJobId <SyncJobService>(Context, 1);

            var millisecs = (long)TimeSpan.FromMinutes(45).TotalMilliseconds;

            var jobInfo = jobBuilder
                          .SetRequiredNetworkType(NetworkType.Any)
                          .SetPeriodic(millisecs)
                          .Build(); // creates a JobInfo object.

            jobScheduler.Schedule(jobInfo);


            // Db Clean

            var cleanJobBuilder = Utilities.CreateJobBuilderUsingJobId <CleanDbJobService>(Context, 1);

            var cleanJobInfo = cleanJobBuilder
                               .SetPeriodic((long)TimeSpan.FromHours(24).TotalMilliseconds)
                               .Build(); // creates a JobInfo object.

            jobScheduler.Schedule(cleanJobInfo);

            // Register Network Callback

            var cm = (ConnectivityManager)GetSystemService(ConnectivityService);

            var builder = new NetworkRequest.Builder();

            _networkCallback = new SyncNetworkCallback();

            if (cm != null)
            {
                cm.RegisterNetworkCallback(builder.Build(), _networkCallback);
            }
#endif
        }