Example #1
0
    private void Awake()
    {
        if (AN_NotificationManager.LastOpenedNotificationRequest != null)
        {
            Debug.Log("Looks like the app was launched from notifications request: "
                      + JsonUtility.ToJson(AN_NotificationManager.LastOpenedNotificationRequest));
        }

        AN_NotificationManager.OnNotificationClick.AddSafeListener(this, (request) => {
            Debug.Log("request.Identifier: " + request.Identifier);
            Debug.Log("User has opened the local notification request with info: " + JsonUtility.ToJson(request));
        });

        AN_NotificationManager.OnNotificationReceived.AddSafeListener(this, (request) => {
            Debug.Log("request.Identifier: " + request.Identifier);
            Debug.Log("notification request received with info: " + JsonUtility.ToJson(request));
        });


        m_withLargeIcon.onClick.AddListener(() => {
            SA_ScreenUtil.TakeScreenshot(256, (screenshot) => {
                var builder = new AN_NotificationCompat.Builder();
                builder.SetContentText("Text");
                builder.SetContentTitle("Title");

                builder.SetLargeIcon(screenshot);
                builder.SetSmallIcon("custom_icon");
                builder.SetSound("slow_spring_board");

                var trigger = new AN_AlarmNotificationTrigger();
                trigger.SetDate(TimeSpan.FromSeconds(1));

                var id      = SA_IdFactory.NextId;
                var request = new AN_NotificationRequest(id, builder, trigger);
                AN_NotificationManager.Schedule(request);
            });
        });


        m_simple.onClick.AddListener(() => {
            var builder = new AN_NotificationCompat.Builder();
            builder.SetContentText("Text 2");
            builder.SetContentTitle("Title 2");

            builder.SetSmallIcon("custom_icon");

            var trigger = new AN_AlarmNotificationTrigger();
            trigger.SetDate(TimeSpan.FromSeconds(5));

            var id      = SA_IdFactory.NextId;
            var request = new AN_NotificationRequest(id, builder, trigger);

            AN_NotificationManager.Schedule(request);
        });


        m_closeApp.onClick.AddListener(() => {
            Application.Quit();
        });
    }
Example #2
0
        public override void Test()
        {
            AN_NotificationManager.CancelAll();

            AN_NotificationManager.Cancel(1);
            AN_NotificationManager.Unschedule(1);


            AN_NotificationManager.OnNotificationReceived.AddListener((request) => {
                bool requestValid = ValidateRequest(request);
                if (requestValid)
                {
                    variant++;
                    TestNotificationWithVariantId(variant);
                }
                else
                {
                    string msg = "Received request does not match sent request   received: " +
                                 JsonUtility.ToJson(request) + " sent: " + JsonUtility.ToJson(m_sendedRequest);
                    SetResult(SA_TestResult.WithError(msg));
                }
            });

            TestNotificationWithVariantId(variant);
        }
        void CancelAllNotifications()
        {
            AN_NotificationManager.UnscheduleAll();
            AN_NotificationManager.CancelAll();
            _currentNotificationScheduleCue = 0;

            Debug.Log("Cancelling all scheduled local notifications");
        }
Example #4
0
        protected override void AddNotificationRequestInternal(UM_NotificationRequest request, Action <SA_Result> callback)
        {
            try
            {
                var builder = new AN_NotificationCompat.Builder();
                builder.SetContentTitle(request.Content.Title);
                builder.SetContentText(request.Content.Body);
                if (request.Content.BadgeNumber != -1)
                {
                    builder.SetNumber(request.Content.BadgeNumber);
                }

                if (string.IsNullOrEmpty(request.Content.SoundName))
                {
                    builder.SetDefaults(AN_Notification.DEFAULT_LIGHTS | AN_Notification.DEFAULT_SOUND);
                }
                else
                {
                    string soundName = SA_AssetDatabase.GetAssetNameWithoutExtension(request.Content.SoundName);
                    builder.SetSound(soundName);
                }


                if (!string.IsNullOrEmpty(request.Content.IconName))
                {
                    string iconName = SA_AssetDatabase.GetAssetNameWithoutExtension(request.Content.IconName);
                    builder.SetSmallIcon(iconName);
                }

                if (request.Content.LargeIcon != null)
                {
                    builder.SetLargeIcon(request.Content.LargeIcon);
                }


                UM_TimeIntervalNotificationTrigger timeIntervalTrigger = (UM_TimeIntervalNotificationTrigger)request.Trigger;

                var trigger = new AN_AlarmNotificationTrigger();
                trigger.SetDate(TimeSpan.FromSeconds(timeIntervalTrigger.Interval));
                trigger.SerRepeating(timeIntervalTrigger.Repeating);

                var android_request = new AN_NotificationRequest(request.Identifier, builder, trigger);

                AN_NotificationManager.Schedule(android_request);

                callback.Invoke(new SA_Result());
            } catch (Exception ex) {
                var error = new SA_Error(100, ex.Message);
                callback.Invoke(new SA_Result(error));
            }
        }
Example #5
0
    private void AndroidBigTextStyle()
    {
        SA_ScreenUtil.TakeScreenshot(256, (screenshot) => {
            var builder = new AN_NotificationCompat.Builder();
            builder.SetContentText("Big Text Style");
            builder.SetContentTitle("Big TextStyle Title");

            var bigTextStyle = new AN_NotificationCompat.BigTextStyle();
            bigTextStyle.BigText("This is test big text style");
            builder.SetStyle(bigTextStyle);
            builder.SetDefaults(AN_Notification.DEFAULT_ALL);

            var trigger = new AN_AlarmNotificationTrigger();
            trigger.SetDate(TimeSpan.FromSeconds(1));

            var id      = SA_IdFactory.NextId;
            var request = new AN_NotificationRequest(id, builder, trigger);
            AN_NotificationManager.Schedule(request);
        });
    }
        /// <summary>
        /// Schedules local notification
        /// </summary>
        /// <param name="title"></param>
        /// <param name="message"></param>
        /// <param name="triggerTime"></param>
        /// <param name="customIconName"></param>
        public void ScheduleNotification(string title, string message, TimeSpan triggerTime, string customIconName = "rg_push_small_icon")
        {
            var builder = new AN_NotificationCompat.Builder();

            builder.SetContentTitle(title);
            builder.SetContentText(message);

            //setting icon for notifications
            builder.SetSmallIcon(customIconName);

            var trigger = new AN_AlarmNotificationTrigger();

            trigger.SetDate(triggerTime);

            var notificationId = _currentNotificationScheduleCue;
            var nRequest       = new AN_NotificationRequest(notificationId, builder, trigger);

            Debug.Log("Local Notification Scheduled in: " + triggerTime + ", invoking: " + title + ", current queue ID: " + _currentNotificationScheduleCue);

            //increase the queue ID
            _currentNotificationScheduleCue++;

            AN_NotificationManager.Schedule(nRequest);
        }
Example #7
0
        public override void Test()
        {
            if (AN_Build.VERSION.SDK_INT >= AN_Build.VERSION_CODES.O)
            {
                string channelId   = "my_channel_id";
                string name        = "My Channel Name";
                string description = "My Channel Description";
                var    importance  = AN_NotificationManager.Importance.DEFAULT;


                AN_NotificationChannel channel = new AN_NotificationChannel(channelId, name, importance);
                channel.Description = description;

                // Register the channel with the system; you can't change the importance
                // or other notification behaviors after this
                AN_NotificationManager.CreateNotificationChannel(channel);


                //Now let's Read notification channel settings and make sure we have our chnnael registred
                List <AN_NotificationChannel> channels;
                channels = AN_NotificationManager.GetNotificationChannels();
                bool found = false;
                foreach (var stsChannel in channels)
                {
                    PrintChannelInfo(stsChannel);
                    if (stsChannel.Id.Equals(channelId))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    SetResult(SA_TestResult.WithError("The Notification Channel wasn't registred in the system"));
                    return;
                }


                channel = AN_NotificationManager.GetNotificationChannel(channelId);
                if (channel == null)
                {
                    SetResult(SA_TestResult.WithError("The Notification Channel wasn't registred in the system"));
                    return;
                }
                else
                {
                    PrintChannelInfo(channel);
                }


                AN_NotificationManager.DeleteNotificationChannel(channelId);


                channels = AN_NotificationManager.GetNotificationChannels();
                found    = false;
                foreach (var stsCahnnel in channels)
                {
                    PrintChannelInfo(stsCahnnel);
                    if (stsCahnnel.Id.Equals(channelId))
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    SetResult(SA_TestResult.WithError("The Notification Channel wasn't deleted from the system"));
                    return;
                }


                SetResult(SA_TestResult.OK);
            }
            else
            {
                SetResult(SA_TestResult.WithError("Notification Channels can only be tested on android 8.0 oreo (api 26) or higher"));
            }
        }
Example #8
0
 public void RemoveDeliveredNotification(int identifier)
 {
     AN_NotificationManager.Cancel(identifier);
 }
Example #9
0
 public void RemovePendingNotification(int identifier)
 {
     AN_NotificationManager.Unschedule(identifier);
 }
Example #10
0
 public void RemoveAllDeliveredNotifications()
 {
     AN_NotificationManager.CancelAll();
 }
Example #11
0
 public void RemoveAllPendingNotifications()
 {
     AN_NotificationManager.UnscheduleAll();
 }
Example #12
0
        private void TestNotificationWithVariantId(int variantId)
        {
            var builder = new AN_NotificationCompat.Builder();


            //should be created automatically
            builder.SetChanelId("test_chanel");
            var icon = SA_IconManager.GetIcon(Color.cyan, 32, 32);

            builder.SetLargeIcon(icon);


            var trigger = new AN_AlarmNotificationTrigger();

            trigger.SetDate(TimeSpan.FromSeconds(1));

            int id = SA_IdFactory.NextId;


            switch (variantId)
            {
            case 1:
                builder.SetContentText("Default");
                builder.SetContentTitle("SetDefaults Test");
                builder.SetDefaults(AN_Notification.DEFAULT_LIGHTS | AN_Notification.DEFAULT_SOUND);
                break;

            case 2:

                builder.SetContentText("BigTextStyle");
                builder.SetContentTitle("BigTextStyle Title");

                var bigTextStyle = new AN_NotificationCompat.BigTextStyle();
                bigTextStyle.BigText("This is test big text style");
                builder.SetStyle(bigTextStyle);
                builder.SetDefaults(AN_Notification.DEFAULT_ALL);
                break;

            case 3:

                builder.SetContentText("BigPictureStyle");
                builder.SetContentTitle("BigPictureStyle title");

                var bigPictureStyle = new AN_NotificationCompat.BigPictureStyle();
                bigPictureStyle.BigPicture(SA_IconManager.GetIcon(Color.red, 32, 32));
                bigPictureStyle.BigLargeIcon(SA_IconManager.GetIcon(Color.green, 32, 32));
                builder.SetStyle(bigPictureStyle);
                builder.SetDefaults(AN_Notification.DEFAULT_ALL);
                break;
            }


            if (variantId == 4)
            {
                SetResult(SA_TestResult.OK);
            }
            else
            {
                m_sendedRequest = new AN_NotificationRequest(id, builder, trigger);
                AN_NotificationManager.Schedule(m_sendedRequest);
            }
        }