public void ScheduleCustom()
        {
            // TODO: Please note, that receiving callback will not work if your app was sleeping. It will only work if app was opened (not resumed) by clicking the notification.

            var notificationParams = new NotificationParams
            {
                Id             = NotificationIdHandler.GetNotificationId(),
                Delay          = TimeSpan.FromSeconds(5),
                Title          = "Custom notification",
                Message        = "Message",
                Ticker         = "Ticker",
                Sound          = true,
                Vibrate        = true,
                Vibration      = new[] { 500, 500, 500, 500, 500, 500 },
                Light          = true,
                LightOnMs      = 1000,
                LightOffMs     = 1000,
                LightColor     = Color.red,
                SmallIcon      = NotificationIcon.Biohazard,
                SmallIconColor = new Color(0, 0.5f, 0),
                LargeIcon      = "app_icon",
                ExecuteMode    = NotificationExecuteMode.Inexact,
                CallbackData   = "notification created at " + DateTime.Now
            };

            NotificationManager.SendCustom(notificationParams);
        }
Example #2
0
        public void ScheduleCustom()
        {
            var notificationParams = new NotificationParams
            {
                Id      = NotificationIdHandler.GetNotificationId(),
                Delay   = TimeSpan.FromSeconds(5),
                Title   = "Notification with callback",
                Message = "Open app and check the checkbox!",
                Ticker  = "Notification with callback",
                Sound   = true,
                //CustomSound = "ding", // AAR\res\raw\ding.wav. Please refer to plugin manual to learn how to add custom sounds.
                Vibrate        = true,
                Vibration      = new[] { 500, 500, 500, 500, 500, 500 },
                Light          = true,
                LightOnMs      = 1000,
                LightOffMs     = 1000,
                LightColor     = Color.red,
                SmallIcon      = NotificationIcon.Sync,
                SmallIconColor = new Color(0f, 0.5f, 0f),
                LargeIcon      = "app_icon",
                ExecuteMode    = NotificationExecuteMode.Inexact,
                Importance     = NotificationImportance.Max,
                CallbackData   = "notification created at " + DateTime.Now
            };

            NotificationManager.SendCustom(notificationParams);
        }
        public static void AddScheduledNotificaion(int notificationId)
        {
            List <int> scheduledNotificaions = NotificationIdHandler.GetScheduledNotificaions();

            scheduledNotificaions.Add(notificationId);
            NotificationIdHandler.SetScheduledNotificaions(scheduledNotificaions);
        }
Example #4
0
        public void ScheduleRepeated()
        {
            NotificationParams notificationParams = new NotificationParams
            {
                Id        = NotificationIdHandler.GetNotificationId(),
                Delay     = TimeSpan.FromSeconds(5.0),
                Title     = "Repeated notification",
                Message   = "Please rate the asset on the Asset Store!",
                Ticker    = "This is repeated message ticker!",
                Sound     = true,
                Vibrate   = true,
                Vibration = new int[]
                {
                    500,
                    500,
                    500,
                    500,
                    500,
                    500
                },
                Light          = true,
                LightOnMs      = 1000,
                LightOffMs     = 1000,
                LightColor     = Color.magenta,
                SmallIcon      = NotificationIcon.Skull,
                SmallIconColor = new Color(0f, 0.5f, 0f),
                LargeIcon      = "app_icon",
                ExecuteMode    = NotificationExecuteMode.Inexact,
                Repeat         = true,
                RepeatInterval = TimeSpan.FromSeconds(30.0)
            };

            NotificationManager.SendCustom(notificationParams);
        }
        public static void RemoveScheduledNotificaion(int id)
        {
            List <int> scheduledNotificaions = NotificationIdHandler.GetScheduledNotificaions();

            scheduledNotificaions.RemoveAll((int i) => i == id);
            NotificationIdHandler.SetScheduledNotificaions(scheduledNotificaions);
        }
Example #6
0
        /// <summary>
        /// Schedule customizable notification.
        /// </summary>
        public static int SendCustom(NotificationParams notificationParams)
        {
            #if UNITY_EDITOR
            Debug.LogWarning("Simple Android Notifications are not supported for current platform. Build and play this scene on android device!");
            #elif UNITY_ANDROID
            var p              = notificationParams;
            var delay          = (long)p.Delay.TotalMilliseconds;
            var repeatInterval = p.Repeat ? (long)p.RepeatInterval.TotalMilliseconds : 0;
            var vibration      = string.Join(",", p.Vibration.Select(i => i.ToString()).ToArray());

            new AndroidJavaClass(FullClassName).CallStatic("SetNotification", p.Id, p.GroupName ?? "", p.GroupSummary ?? "", p.ChannelId, p.ChannelName, delay, Convert.ToInt32(p.Repeat), repeatInterval, p.Title, p.Message, p.Ticker, Convert.ToInt32(p.Multiline),
                                                           Convert.ToInt32(p.Sound), p.CustomSound ?? "", Convert.ToInt32(p.Vibrate), vibration, Convert.ToInt32(p.Light), p.LightOnMs, p.LightOffMs, ColotToInt(p.LightColor), p.LargeIcon ?? "", GetSmallIconName(p.SmallIcon), ColotToInt(p.SmallIconColor), (int)p.ExecuteMode, p.CallbackData, MainActivityClassName);

            NotificationIdHandler.AddScheduledNotificaion(p.Id);
            #elif UNITY_IPHONE
            var notification = new UnityEngine.iOS.LocalNotification
            {
                hasAction = false,
                alertBody = notificationParams.Message,
                fireDate  = DateTime.Now.Add(notificationParams.Delay)
            };

            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);
            #endif

            return(notificationParams.Id);
        }
Example #7
0
        public void ScheduleCustom()
        {
            NotificationParams notificationParams = new NotificationParams
            {
                Id        = NotificationIdHandler.GetNotificationId(),
                Delay     = TimeSpan.FromSeconds(5.0),
                Title     = "Notification with callback",
                Message   = "Open app and check the checkbox!",
                Ticker    = "Notification with callback",
                Sound     = true,
                Vibrate   = true,
                Vibration = new int[]
                {
                    500,
                    500,
                    500,
                    500,
                    500,
                    500
                },
                Light          = true,
                LightOnMs      = 1000,
                LightOffMs     = 1000,
                LightColor     = Color.red,
                SmallIcon      = NotificationIcon.Sync,
                SmallIconColor = new Color(0f, 0.5f, 0f),
                LargeIcon      = "app_icon",
                ExecuteMode    = NotificationExecuteMode.Inexact,
                CallbackData   = "notification created at " + DateTime.Now
            };

            NotificationManager.SendCustom(notificationParams);
        }
        public void ScheduleRepeated()
        {
            var notificationParams = new NotificationParams
            {
                Id             = NotificationIdHandler.GetNotificationId(),
                Delay          = TimeSpan.FromSeconds(5),
                Title          = "Repeated notification",
                Message        = "Message",
                Ticker         = "Ticker",
                Sound          = true,
                Vibrate        = true,
                Vibration      = new[] { 500, 500, 500, 500, 500, 500 },
                Light          = true,
                LightOnMs      = 1000,
                LightOffMs     = 1000,
                LightColor     = Color.magenta,
                SmallIcon      = NotificationIcon.Skull,
                SmallIconColor = new Color(0, 0.5f, 0),
                LargeIcon      = "app_icon",
                ExecuteMode    = NotificationExecuteMode.Exact,
                Repeat         = true,
                RepeatInterval = TimeSpan.FromSeconds(5) // Don't use short intervals as repeated notifications are inexact
            };

            NotificationManager.SendCustom(notificationParams);
        }
Example #9
0
        /// <summary>
        /// Cancel notification by id.
        /// </summary>
        public static void Cancel(int id)
        {
            #if UNITY_ANDROID && !UNITY_EDITOR
            new AndroidJavaClass(FullClassName).CallStatic("CancelNotification", id);

            NotificationIdHandler.RemoveScheduledNotificaion(id);
            #endif
        }
Example #10
0
        /// <summary>
        /// Cancel all displayed notifications only.
        /// </summary>
        public static void CancelAllDisplayed()
        {
            #if UNITY_ANDROID && !UNITY_EDITOR
            new AndroidJavaClass(FullClassName).CallStatic("CancelAllDisplayedNotifications");

            NotificationIdHandler.RemoveAllScheduledNotificaions();
            #endif
        }
 public static void Cancel(int id)
 {
     new AndroidJavaClass("com.hippogames.simpleandroidnotifications.Controller").CallStatic("CancelNotification", new object[]
     {
         id
     });
     NotificationIdHandler.RemoveScheduledNotificaion(id);
 }
Example #12
0
        public void Repeating()
        {
            var isClicked = PlayerPrefsX.GetBool("ClickedRepeating");

            if (isClicked)
            {
                Debug.Log("sending out comps for each");
                repeatingIDList.Clear();
                int compNumber = 0;
                foreach (string comp in complimentStrings.compList)
                {
                    //this gets the index number of each comp;
                    compNumber = complimentStrings.compList.IndexOf(comp);
                    var notificationParams = new NotificationParams {
                        Id = NotificationIdHandler.GetNotificationId(),
                        //adds 1 to each int and then times it by the delay, so each string happens with delay between it;
                        Delay          = TimeSpan.FromSeconds((compNumber + 1) * 18000),
                        Title          = "Hi",
                        Message        = comp,
                        Ticker         = ":)",
                        Sound          = false,
                        Vibrate        = true,
                        Vibration      = new[] { 500, 500, 500, 500, 500, 500 },
                        Light          = true,
                        LightOnMs      = 1000,
                        LightOffMs     = 1000,
                        LightColor     = Color.magenta,
                        SmallIcon      = NotificationIcon.Star,
                        SmallIconColor = new Color(0f, 0.5f, 0f),
                        LargeIcon      = "app_icon",
                        ExecuteMode    = NotificationExecuteMode.Inexact,
                        Repeat         = true,
                        RepeatInterval = TimeSpan.FromSeconds(UnityEngine.Random.Range(180000, 266400))                           // Don't use short intervals as repeated notifications are always inexact
                    };
                    //add these IDs to a list and then turn it into an array,so that we cancel just these Ids later
                    eachBoolID = notificationParams.Id;
                    repeatingIDList.Add(eachBoolID);
                    Debug.Log("adding this id to list" + eachBoolID);
                    int[] repeatingIDArray = repeatingIDList.ToArray();
                    PlayerPrefsX.SetIntArray("RepeatingIDs", repeatingIDArray);
                    NotificationManager.SendCustom(notificationParams);
                }
            }
            if (!isClicked)
            {
                Debug.Log("stopping comps");
                //get the array and turn it into a list, and then for every id cancel it
                int [] repeatingIDArray = PlayerPrefsX.GetIntArray("RepeatingIDs");
                foreach (int id in repeatingIDArray)
                {
                    Debug.Log("cancelling" + id);
                    NotificationManager.Cancel(id);
                    startRepeatingButton.Colour();
                }
                //clears list
                repeatingIDList.Clear();
            }
        }
        public static int GetNotificationId()
        {
            List <int> scheduledNotificaions = NotificationIdHandler.GetScheduledNotificaions();
            int        num;

            do
            {
                num = Random.Range(0, int.MaxValue);
            }while (scheduledNotificaions.Contains(num));
            return(num);
        }
Example #14
0
        public static int SendCustom(NotificationParams notificationParams)
        {
            NotificationParams notificationParam = notificationParams;
            long   totalMilliseconds             = (long)notificationParam.Delay.TotalMilliseconds;
            long   num = (!notificationParam.Repeat ? (long)0 : (long)notificationParam.RepeatInterval.TotalMilliseconds);
            string str = string.Join(",", (
                                         from i in (IEnumerable <int>)notificationParam.Vibration
                                         select i.ToString()).ToArray <string>());

            (new AndroidJavaClass("com.hippogames.simpleandroidnotifications.Controller")).CallStatic("SetNotification", new object[] { notificationParam.Id, notificationParam.GroupName ?? string.Empty, notificationParam.GroupSummary ?? string.Empty, notificationParam.ChannelId, notificationParam.ChannelName, totalMilliseconds, Convert.ToInt32(notificationParam.Repeat), num, notificationParam.Title, notificationParam.Message, notificationParam.Ticker, Convert.ToInt32(notificationParam.Multiline), Convert.ToInt32(notificationParam.Sound), notificationParam.CustomSound ?? string.Empty, Convert.ToInt32(notificationParam.Vibrate), str, Convert.ToInt32(notificationParam.Light), notificationParam.LightOnMs, notificationParam.LightOffMs, NotificationManager.ColotToInt(notificationParam.LightColor), notificationParam.LargeIcon ?? string.Empty, NotificationManager.GetSmallIconName(notificationParam.SmallIcon), NotificationManager.ColotToInt(notificationParam.SmallIconColor), (int)notificationParam.ExecuteMode, notificationParam.CallbackData, "com.blizzard.wowcompanion.CompanionNativeActivity" });
            NotificationIdHandler.AddScheduledNotificaion(notificationParam.Id);
            return(notificationParams.Id);
        }
Example #15
0
        public void ScheduleMultiline()
        {
            NotificationParams notificationParams = new NotificationParams
            {
                Id        = NotificationIdHandler.GetNotificationId(),
                Delay     = TimeSpan.FromSeconds(5.0),
                Title     = "Multiline notification",
                Message   = "Line#1\nLine#2\nLine#3\nLine#4",
                Ticker    = "This is multiline message ticker!",
                Multiline = true
            };

            NotificationManager.SendCustom(notificationParams);
        }
Example #16
0
        public static int GetNotificationId()
        {
            int        num;
            List <int> scheduledNotificaions = NotificationIdHandler.GetScheduledNotificaions();

            while (true)
            {
                num = UnityEngine.Random.Range(0, 2147483647);
                if (!scheduledNotificaions.Contains(num))
                {
                    break;
                }
            }
            return(num);
        }
Example #17
0
        public void ScheduleWithChannel()
        {
            NotificationParams notificationParams = new NotificationParams
            {
                Id          = NotificationIdHandler.GetNotificationId(),
                Delay       = TimeSpan.FromSeconds(5.0),
                Title       = "Notification with news channel",
                Message     = "Check the channel in your app settings!",
                Ticker      = "Notification with news channel",
                ChannelId   = "com.company.app.news",
                ChannelName = "News"
            };

            NotificationManager.SendCustom(notificationParams);
        }
Example #18
0
        public void ScheduleGrouped()
        {
            int notificationId = NotificationIdHandler.GetNotificationId();
            NotificationParams notificationParams = new NotificationParams
            {
                Id           = notificationId,
                GroupName    = "Group",
                GroupSummary = "{0} new messages",
                Delay        = TimeSpan.FromSeconds(5.0),
                Title        = "Grouped notification",
                Message      = "Message " + notificationId,
                Ticker       = "Please rate the asset on the Asset Store!"
            };

            NotificationManager.SendCustom(notificationParams);
        }
Example #19
0
        /// <summary>
        /// Schedule customizable notification.
        /// </summary>
        public static int SendCustom(NotificationParams notificationParams)
        {
            #if UNITY_ANDROID && !UNITY_EDITOR
            var p              = notificationParams;
            var delay          = (long)p.Delay.TotalMilliseconds;
            var repeatInterval = p.Repeat ? (long)p.RepeatInterval.TotalMilliseconds : 0;
            var vibration      = string.Join(",", p.Vibration.Select(i => i.ToString()).ToArray());

            new AndroidJavaClass(FullClassName).CallStatic("SetNotification", p.Id, delay, p.Repeat ? 1 : 0, repeatInterval, p.Title, p.Message, p.Ticker,
                                                           p.Sound ? 1 : 0, p.Vibrate ? 1 : 0, vibration, p.Light ? 1 : 0, p.LightOnMs, p.LightOffMs, ColotToInt(p.LightColor), p.LargeIcon, GetSmallIconName(p.SmallIcon), ColotToInt(p.SmallIconColor), (int)p.ExecuteMode, p.CallbackData, MainActivityClassName);

            NotificationIdHandler.AddScheduledNotificaion(p.Id);
            #else
            Debug.LogWarning("Simple Android Notifications are not supported for current platform. Build and play this scene on android device!");
            #endif

            return(notificationParams.Id);
        }
 public static int SendWithAppIcon(TimeSpan delay, string title, string message, Color smallIconColor, NotificationIcon smallIcon = NotificationIcon.Bell, bool silent = false)
 {
     return(NotificationManager.SendCustom(new NotificationParams
     {
         Id = NotificationIdHandler.GetNotificationId(),
         Delay = delay,
         Title = title,
         Message = message,
         Ticker = message,
         Sound = !silent,
         Vibrate = !silent,
         Light = true,
         SmallIcon = smallIcon,
         SmallIconColor = smallIconColor,
         LargeIcon = "app_icon",
         ExecuteMode = NotificationExecuteMode.Inexact
     }));
 }
Example #21
0
        public static int Send(TimeSpan delay, string title, string message, Color smallIconColor, NotificationIcon smallIcon = 0, bool silent = false)
        {
            NotificationParams notificationParam = new NotificationParams()
            {
                Id             = NotificationIdHandler.GetNotificationId(),
                Delay          = delay,
                Title          = title,
                Message        = message,
                Ticker         = message,
                Sound          = !silent,
                Vibrate        = !silent,
                Light          = true,
                SmallIcon      = smallIcon,
                SmallIconColor = smallIconColor,
                LargeIcon      = string.Empty,
                ExecuteMode    = NotificationExecuteMode.Inexact
            };

            return(NotificationManager.SendCustom(notificationParam));
        }
        public static int SendCustom(NotificationParams notificationParams)
        {
            long   num  = (long)notificationParams.Delay.TotalMilliseconds;
            long   num2 = (!notificationParams.Repeat) ? 0L : ((long)notificationParams.RepeatInterval.TotalMilliseconds);
            string text = string.Join(",", (from i in notificationParams.Vibration
                                            select i.ToString()).ToArray <string>());

            new AndroidJavaClass("com.hippogames.simpleandroidnotifications.Controller").CallStatic("SetNotification", new object[]
            {
                notificationParams.Id,
                notificationParams.GroupName ?? string.Empty,
                notificationParams.GroupSummary ?? string.Empty,
                notificationParams.ChannelId,
                notificationParams.ChannelName,
                num,
                Convert.ToInt32(notificationParams.Repeat),
                num2,
                notificationParams.Title,
                notificationParams.Message,
                notificationParams.Ticker,
                Convert.ToInt32(notificationParams.Multiline),
                Convert.ToInt32(notificationParams.Sound),
                notificationParams.CustomSound ?? string.Empty,
                Convert.ToInt32(notificationParams.Vibrate),
                text,
                Convert.ToInt32(notificationParams.Light),
                notificationParams.LightOnMs,
                notificationParams.LightOffMs,
                NotificationManager.ColotToInt(notificationParams.LightColor),
                notificationParams.LargeIcon ?? string.Empty,
                NotificationManager.GetSmallIconName(notificationParams.SmallIcon),
                NotificationManager.ColotToInt(notificationParams.SmallIconColor),
                (int)notificationParams.ExecuteMode,
                (int)notificationParams.Importance,
                notificationParams.CallbackData,
                "com.google.firebase.MessagingUnityPlayerActivity"
            });
            NotificationIdHandler.AddScheduledNotificaion(notificationParams.Id);
            return(notificationParams.Id);
        }
 public static void RemoveAllScheduledNotificaions()
 {
     NotificationIdHandler.SetScheduledNotificaions(new List <int>());
 }
 public static void CancelAllDisplayed()
 {
     new AndroidJavaClass("com.hippogames.simpleandroidnotifications.Controller").CallStatic("CancelAllDisplayedNotifications", new object[0]);
     NotificationIdHandler.RemoveAllScheduledNotificaions();
 }