示例#1
0
        /// <summary>
        /// Repetitive notification
        /// </summary>
        public void RepeatingNotificationSample()
        {
            int    id    = 1;
            string title = "New repeating notification";
            string body  = "You have some unfinished business!";

            // Show notification in 5 minutes
            TimeSpan delay = new TimeSpan(0, 5, 0);

            // Show notification with 10 minute interval
            TimeSpan interval = new TimeSpan(0, 10, 0);

            NotificationBuilder builder = new NotificationBuilder(id, title, body);

            builder
            .setDelay(delay)
            .setRepeating(true)
            .setInterval(interval);

            AndroidNotifications.scheduleNotification(builder.build());
        }
示例#2
0
        /// <summary>
        /// Notification with custom icons and sounds
        /// </summary>
        public void CustomIconsAndSoundSample()
        {
            int    id    = 1;
            string title = "Custom icon and sound";
            string body  = "You have some unfinished business!";

            // Show notification in 5 minutes
            TimeSpan delay = new TimeSpan(0, 5, 0);

            // WARNING: in order to this sample to work place the icons with the corresponding names res/drawable folder
            // and sound with corresponding name in res/raw folder
            NotificationBuilder builder = new NotificationBuilder(id, title, body);

            builder
            .setDelay(delay)
            .setSmallIcon("mySmallIcon")
            .setLargeIcon("myLargeIcon")
            .setSound("mySound");

            AndroidNotifications.scheduleNotification(builder.build());
        }
示例#3
0
        public static NotificationBuilder FromInstance(NotificationInstance notif)
        {
            NotificationBuilder builder = new NotificationBuilder(notif.id, notif.title, notif.body);

            if (notif.smallIcon != null)
            {
                builder.setSmallIcon(notif.smallIcon.name);
            }
            if (notif.largeIcon != null)
            {
                builder.setLargeIcon(notif.largeIcon.name);
            }
            if ((notif.ticker != null) && (notif.ticker.Length > 0))
            {
                builder.setTicker(notif.ticker);
            }
            int defaultFlags = 0;

            if (notif.defaultSound)
            {
                defaultFlags |= 1;
            }
            else if (notif.soundFile != null)
            {
                builder.setSound(notif.soundFile.name);
            }
            if (notif.defaultVibrate)
            {
                defaultFlags |= 2;
            }
            else if (notif.vibroPattern != null)
            {
                long[] pattern = notif.vibroPattern.ToArray();
                builder.setVibrate(pattern);
            }
            if (defaultFlags > 0)
            {
                builder.setDefaults(defaultFlags);
            }
            if (notif.number > 0)
            {
                builder.setNumber(notif.number);
            }
            if ((notif.group != null) && (notif.group.Length > 0))
            {
                builder.setGroup(notif.group);
            }
            if ((notif.sortKey != null) && (notif.sortKey.Length > 0))
            {
                builder.setSortKey(notif.sortKey);
            }
            if (notif.hasColor)
            {
                builder.setColor("#" + ColorUtils.ToHtmlStringRGB(notif.color));
            }
            builder.setGroupId(notif.groupId);
            builder.setAutoCancel(notif.autoCancel);
            builder.setAlertOnlyOnce(notif.alertOnce);
            if (notif.isRepeating)
            {
                builder.setRepeating(true);
                long num2     = ((notif.intervalHours * 0xe10) + (notif.intervalMinutes * 60)) + notif.intervalSeconds;
                long interval = num2 * 0x3e8L;
                builder.setInterval(interval);
            }
            long num4 = ((notif.delayHours * 0xe10) + (notif.delayMinutes * 60)) + notif.delaySeconds;
            long delayMilliseconds = num4 * 0x3e8L;

            builder.setDelay(delayMilliseconds);
            return(builder);
        }
        /// <summary>
        /// Builds notification from NotificationInstance - created in editor
        /// </summary>
        /// <param name="notif">Instance created in Notifications Window</param>
        /// <returns>Notification buildder</returns>
        public static NotificationBuilder FromInstance(NotificationInstance notif)
        {
            NotificationBuilder builder = new NotificationBuilder(notif.id, notif.title, notif.body);

            if (notif.smallIcon != null)
            {
                builder.setSmallIcon(notif.smallIcon.name);
            }

            if (notif.largeIcon != null)
            {
                builder.setLargeIcon(notif.largeIcon.name);
            }

            if (notif.ticker != null && notif.ticker.Length > 0)
            {
                builder.setTicker(notif.ticker);
            }

            int defaults = 0;

            // Handle sound
            if (notif.defaultSound)
            {
                defaults |= NotificationBuilder.DEFAULT_SOUND;
            }
            else
            {
                if (notif.soundFile != null)
                {
                    builder.setSound(notif.soundFile.name);
                }
            }

            // Handle vibrate
            if (notif.defaultVibrate)
            {
                defaults |= NotificationBuilder.DEFAULT_VIBRATE;
            }
            else
            {
                if (notif.vibroPattern != null)
                {
                    long[] vibratePattern = notif.vibroPattern.ToArray();
                    builder.setVibrate(vibratePattern);
                }
            }

            if (defaults > 0)
            {
                builder.setDefaults(defaults);
            }

            if (notif.number > 0)
            {
                builder.setNumber(notif.number);
            }

            if (notif.group != null && notif.group.Length > 0)
            {
                builder.setGroup(notif.group);
            }

            if (notif.sortKey != null && notif.sortKey.Length > 0)
            {
                builder.setSortKey(notif.sortKey);
            }

            if (notif.hasColor)
            {
                builder.setColor("#" + ColorUtility.ToHtmlStringRGB(notif.color));
            }

            builder.setAutoCancel(notif.autoCancel);
            builder.setAlertOnlyOnce(notif.alertOnce);

            // Repeating and interval
            if (notif.isRepeating)
            {
                builder.setRepeating(true);

                long intervalSeconds = notif.intervalHours * 3600 + notif.intervalMinutes * 60 + notif.intervalSeconds;
                long milis           = intervalSeconds * 1000;

                builder.setInterval(milis);
            }

            // Delay
            long delaySeconds = notif.delayHours * 3600 + notif.delayMinutes * 60 + notif.delaySeconds;
            long delayMilis   = delaySeconds * 1000;

            builder.setDelay(delayMilis);

            return(builder);
        }