Scheduling a local Notification with System Date and notifies without launching the App (Xamarin.For

Am trying to schedule a local notification depending on the time set in SQLite , I am using a certain library in this link :

[local Notification library][1]

I have implemented it well, but am still facing the problems below:

a) The notification comes only when I launch the App.

b)All notification time notifies once which are stored locally in SQLite.

Now how can I make this Application to capture the system time (Phone time)
and it notifies like an Alarm without even launching the Application

Am I supposed to use one of these methods:

i) OnSleep

ii)OnResume etc or...

So below is how I was placing my code in App.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using Diabetes.localDB;
using Diabetes.Main;
using Newtonsoft.Json;
using Plugin.Notifications;
using Xamarin.Forms;

namespace Diabetes
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            // Setting the Alarm time 
            MedicationDatabase db = new MedicationDatabase();
            //Getting  list of time set in SQlite.
            var alarm_list = db.GetAlarmList();

            // Looping each time to make an alarm
            foreach (var alarm in alarm_list)
            {
                try
                {

                    Debug.WriteLine("Date Time Format : " + alarm);

                //This is the library to set Notifications, Date is where the time is attached.
                    CrossNotifications.Current.Send(new Notification
                    {
                        Title = "Hola! ",
                        Message = "Hey  Eddy I remind you take insulin, this is the time you told me to remind you.",
                        Vibrate = true,
                        Sound = "pop",
                        Date = DateTime.Parse(alarm)

                    });
                }
                catch (FormatException v)
                {
                    Debug.WriteLine("Format Exception : " + v);
                }
                catch (OverflowException c)
                {
                    Debug.WriteLine("Overflow Exception : " + c);
                }


            }

            MainPage = new NavigationPage(new Login())

            {
                BarBackgroundColor = Color.FromHex("#66C8F3"),
                BarTextColor = Color.White,
                Title = "Diabetics App"


            };
        }

        protected override void OnStart()
        {


        }



        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }





    }
}
Tagged:

Answers

Sign In or Register to comment.