-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScheduledAlarmHandler.cs
More file actions
37 lines (34 loc) · 1.38 KB
/
ScheduledAlarmHandler.cs
File metadata and controls
37 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.IO;
using System.Xml.Serialization;
using Android.Content;
using CoreServices.LocalNotificationsServices;
using Xamarin.Forms;
namespace BaseTemplate.Droid.Services.LocalNotificationService
{
/// <summary>
/// Broadcast receiver
/// </summary>
[BroadcastReceiver(Enabled = true, Label = "Local Notifications Plugin Broadcast Receiver")]
public class ScheduledAlarmHandler : BroadcastReceiver
{
/// <summary>
/// </summary>
public const string LocalNotificationKey = "LocalNotification";
/// <summary>
/// </summary>
/// <param name="context"></param>
/// <param name="intent"></param>
public override void OnReceive(Context context, Intent intent)
{
string extra = intent.GetStringExtra(LocalNotificationKey);
LocalNotification notification = DeserializeNotification(extra);
DependencyService.Get<ILocalNotificationService>().Notify(notification.Title, notification.Body, 12);
}
private static LocalNotification DeserializeNotification(string notificationString)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(LocalNotification));
using StringReader stringReader = new StringReader(notificationString);
return (LocalNotification)xmlSerializer.Deserialize(stringReader);
}
}
}