Exemplo n.º 1
0
        private async Task CheckNotification(IJobParameters @params)
        {
            try
            {
                Log.Debug("PUSTERA_TAG", "Starting notifiation check");

                (Notification notification, string message) = await APIService.CheckNotification();

                if (notification != null)
                {
                    var notifService = new NotificationService(this);
                    notifService.Notify(notification);
                }

                Log.Error("PUSTERA_TAG", "Finished message.." + message + " :");

                Log.Debug("PUSTERA_TAG", "Finished notifiation check.." + notification?.Date ?? "");


                JobFinished(@params, true);

                Log.Debug("PUSTERA_TAG", "Job finished");
            }
            catch (Exception bug)
            {
                Log.Debug("PUSTERA_TAG", bug.Message);
            }
        }
        public override bool OnStartJob(IJobParameters jobParameters)
        {
            int position = jobParameters.Extras.GetInt(FibonacciPositionKey, DEFAULT_VALUE);

            LogMessage($"Starting FibonacciCalculatorJob::OnStartJob. Job tag {jobParameters.Tag}.");

            // Look for the Fibonacci number on a thread - don't bog down the main thread.
            Task.Run(() => GetFibonacciNumberAt(position)).
            ContinueWith(task =>
            {
                // Record the result, so that it will show up in the Main activity.
                IJobHistoryStorage storage = FJDTestApplication.JobHistoryStorage;
                string msg = $"The fibonnaci number at {position} is {task.Result}";
                storage.RecordResult(jobParameters, msg);

                // Have to call JobFinished when the thread is done. This lets the FJD know that
                // the work is done.
                JobFinished(jobParameters, false);
                LogMessage(
                    $"Finished FibonacciCalculatorJob::OnStartJob/Job tag {jobParameters.Tag}. {msg}");
            }, TaskScheduler.FromCurrentSynchronizationContext());

            LogMessage("Leaving FibonacciCalculatorJob::OnStartJob.");


            return(false); // No more work to do, so return false.
        }
Exemplo n.º 3
0
        public override bool OnStartJob(IJobParameters jobParameters)
        {
            Log.Error("lv", "11111111111111111111111");
            Intent                    notIntent     = new Intent(this, typeof(MainActivity));
            PendingIntent             contentIntent = PendingIntent.GetActivity(this, 0, notIntent, PendingIntentFlags.UpdateCurrent);
            NotificationManagerCompat manager       = NotificationManagerCompat.From(this);

            var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.pause));

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetContentIntent(contentIntent)
                                                 .SetSmallIcon(Resource.Drawable.play)
                                                 .SetContentTitle("title")
                                                 .SetContentText("message")
                                                 .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .Extend(wearableExtender);

            Notification notification = builder.Build();

            notification.Flags = NotificationFlags.AutoCancel;
            manager.Notify(0, notification);
            JobFinished(jobParameters, false);
            return(true);
        }
Exemplo n.º 4
0
 public JobHistory(IJobParameters job)
 {
     if (job == null)
     {
         throw new NullReferenceException("Must provide a valid IJobParameters instance!");
     }
     Job = job;
 }
Exemplo n.º 5
0
        public bool IsFor(IJobParameters job)
        {
            if (job == null)
            {
                return(false);
            }

            int jobHashCode = job.Service.GetHashCode() + 11 * job.Tag.GetHashCode();

            return(GetHashCode() == jobHashCode);
        }
Exemplo n.º 6
0
        protected virtual string ToPayload(IJobParameters parameters)
        {
            var s = "";

            foreach (var key in parameters.Keys)
            {
                var value = parameters.Get(key, "");
                s += $"{key}:{value};";
            }
            s = s.TrimEnd(';');
            return(s);
        }
Exemplo n.º 7
0
        public static readonly string TAG = typeof(MeasurementJob).FullName; //unique TAG

        public override bool OnStartJob(IJobParameters jobParameters)
        {
            Task.Run(async() =>
            {
                TestMeViewModel testMeViewModel = new TestMeViewModel();
                //DependencyService.Get<IBand>().SendVibration();
                await MeasurementHandler.ResendIntervals();                    //resend previous measurements if exist
                await MeasurementHandler.GetStressResult(-1, testMeViewModel); //start new measurement. -1 => real measurement
                String[] stressRes = testMeViewModel.StressResult.Split(" ");
                int tempLen        = stressRes.Length;
                if (stressRes[0] != "Error:" && stressRes[tempLen - 2] != "not") //this is a stress moment
                {
                    CrossLocalNotifications.Current.Show("RelaxApp noticed stress", "Tap into the app for more information");
                    EmailService.Execute(); //send mail to Emergency Contact
                }
            });
            return(true);
        }
        public void RecordResult(IJobParameters job, string result)
        {
            if (job == null)
            {
                return;
            }
            JobHistory jobHistory;

            if (jobHistories.Any(arg => arg.IsFor(job)))
            {
                jobHistory = jobHistories.First(arg => arg.IsFor(job));
            }
            else
            {
                jobHistory = new JobHistory(job);
                jobHistories.Add(jobHistory);
            }

            jobHistory.RecordResult(result);
            NotifyChanged();
        }
Exemplo n.º 9
0
        public override bool OnStartJob(IJobParameters jobParameters)
        {
            Task.Run(async() =>
            {
                await SearchPhotoRequest();


                if (StaticBox.IsAvalableRequest == "0")
                {
                    // Create PendingIntent
                    StaticBox.CameraOpenOrNo    = 1;
                    StaticBox.IsAvalableRequest = "1";
                    Intent camera = new Intent(this, typeof(SensorsDataActivity));

                    PendingIntent resultPendingIntent = PendingIntent.GetActivity(this, 0, camera,
                                                                                  PendingIntentFlags.UpdateCurrent);

                    //Create Notification
                    NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context, "Channel")
                                                         .SetSmallIcon(Resource.Mipmap.ic_launcher)
                                                         .SetContentTitle("Запрос клиента на получение фото.")
                                                         .SetContentText("Сделать фото")
                                                         .SetAutoCancel(true)
                                                         .SetVibrate(new long[] { 1000, 1000 })
                                                         .SetContentIntent(resultPendingIntent);

                    //Show Notification
                    Notification notification = builder.Build();
                    NotificationManager notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
                    notificationManager.Notify(1, notification);
                }
                JobFinished(jobParameters, true);
            });

            // Return true because of the asynchronous work
            return(true);
        }
Exemplo n.º 10
0
 public override bool OnStopJob(IJobParameters jobParameters)
 {
     return(false);
 }
Exemplo n.º 11
0
        public override bool OnStartJob(IJobParameters jobParameters)
        {
            updateService.TriggerUpdate();

            return(false);
        }
 public override bool OnStopJob(IJobParameters jobParameters)
 {
     Log.Debug(TAG, "FibonacciCalculatorJob::OnStopJob");
     // nothing to do.
     return(false);
 }
Exemplo n.º 13
0
 public override bool OnStopJob(IJobParameters jobParameters)
 {
     Log.Debug(TAG, "DemoJob::OnStartJob");
     // nothing to do.
     return(true);
 }
Exemplo n.º 14
0
 public override bool OnStartJob(IJobParameters @params)
 {
     CheckNotification(@params);
     return(true);
 }