Ejemplo n.º 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();
        });
    }
Ejemplo n.º 2
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));
            }
        }