Esempio n. 1
0
        private static string SerializeNotification(AndroidNotification notification)
        {
            var xmlSerializer = new XmlSerializer(notification.GetType());

            using (var stringWriter = new StringWriter())
            {
                xmlSerializer.Serialize(stringWriter, notification);
                return(stringWriter.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Show a local notification at a specified time
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        /// <param name="id">Id of the notification</param>
        /// <param name="notifyTime">Time to show notification</param>
        public static void Show(string title, string body, int id, DateTime notifyTime)
        {
            var intent = CreateIntent(id);

            var localNotification = new AndroidNotification
            {
                Title      = title,
                Body       = body,
                Id         = id,
                NotifyTime = notifyTime,
            };

            var serializedNotification = SerializeNotification(localNotification);

            intent.PutExtra(ScheduledAlarmHandler.LocalNotificationKey, serializedNotification);

            var pendingIntent = PendingIntent.GetBroadcast(Application.Context, id, intent, PendingIntentFlags.UpdateCurrent);
            var triggerTime   = NotifyTimeInMilliseconds(localNotification.NotifyTime);

            AlarmManager.Set(AlarmType.RtcWakeup, triggerTime, pendingIntent);
        }