locked
Can I get Alarm Notifications in Xamarin.UWP ?? RRS feed

  • Question

  • User391114 posted

    I want to implement Alarm based Notification in Xamarin.UWP . I have implemented the same alarm notification feature for Xamarin Android and iOS using ILocalNotificationService . But , I am finding it difficult to implement it in UWP platform. My aim is to run the same code on all 3 platforms. So, that I can receive reminders for the meetings.

    Is there any method through which it can be implemented ??? Please let me know.

    Thanks.

    Monday, December 16, 2019 6:22 PM

Answers

  • User371688 posted

    What do you mean by the words meeting/event ?
    If you want to create an appointment and apply DateTime data to it, you can refer this document: https://docs.microsoft.com/en-us/windows/uwp/contacts-and-calendar/managing-appointments

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, December 19, 2019 7:50 AM

All replies

  • User371688 posted

    If you want to make Local notification fore Xamarin.Forms, please refer this document. But it has not implement UWP platform. So we need implement schedule notification within uwp and use dependency service to call it. And here is a simple demo you could refer.

    interface

     public interface INotificationManager
    { 
        int ScheduleNotification(string title, string message,DateTime scheduledTime);   
     }
    

    Implement

    public class UWPNotificationManager : INotificationManager
    { 
      int messageId = -1;
    
     public int ScheduleNotification(string title, string message,DateTime scheduledTime)
     {
    
        messageId++;
        string TOAST = $@"<toast>
                  <visual>
                    <binding template='ToastGeneric'>
                      <text>{title}</text>
                      <text>{message}</text>
                    </binding>
                  </visual>
                  <audio src =""ms-winsoundevent:Notification.Mail"" loop=""true""/>
                </toast>";
    
        Windows.Data.Xml.Dom.XmlDocument xml = new Windows.Data.Xml.Dom.XmlDocument();
        xml.LoadXml(TOAST);
    
        ScheduledToastNotification toast = new ScheduledToastNotification(xml, scheduledTime);
        toast.Id = "IdTostone" + messageId.ToString();
        toast.Tag = "NotificationOne";
        toast.Group = nameof(UWPNotificationManager);
        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
    
        return messageId;
    }
    }
    

    Usage

    private void OnScheduleClick(object sender, EventArgs e)
    {
       notificationNumber++;
       string title = $"Local Notification #{notificationNumber}";
       string message = $"You have now received {notificationNumber} notifications!";
       notificationManager.ScheduleNotification(title, message,DateTime.Now + TimeSpan.FromSeconds(3));
      }
    
    Tuesday, December 17, 2019 9:11 AM
  • User391114 posted

    Hi jezh,

    Thanks for your reply!

    But, I have tried this code earlier. But , the issue is that I am not able to set an alarm for the timePicker which I am implementing in my event form. I want to use schedule functionality that can remind me before any meeting/event.

    So , do have any suggestions for me regarding this reminder alarm using xamarin forms ???

    Tuesday, December 17, 2019 2:19 PM
  • User371688 posted

    What do you mean by the words meeting/event ?
    If you want to create an appointment and apply DateTime data to it, you can refer this document: https://docs.microsoft.com/en-us/windows/uwp/contacts-and-calendar/managing-appointments

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, December 19, 2019 7:50 AM
  • User391114 posted

    I have implemented the code. Its working great now.

    Thanks.

    Friday, December 20, 2019 4:44 PM