Esempio n. 1
0
        /// <summary>
        ///  Creates a notification channel that notifications can be posted to.
        ///  Notification channel settings can be changed by users on devices running Android 8.0 and above.
        ///  On older Android versions settings set on the notification channel struct will still be applied to the notification
        ///  if they are supported to by the Android version the app is running on.
        /// </summary>
        /// <remarks>
        ///  When a channel is deleted and recreated, all of the previous settings are restored. In order to change any settings
        ///  besides the name or description an entirely new channel (with a different channel ID) must be created.
        /// </remarks>
        public static void RegisterNotificationChannel(AndroidNotificationChannel channel)
        {
            if (!Initialize())
            {
                return;
            }

            if (string.IsNullOrEmpty(channel.id))
            {
                throw new Exception("Cannot register notification channel, the channel ID is not specified.");
            }
            else if (string.IsNullOrEmpty(channel.id))
            {
                throw new Exception(string.Format("Cannot register notification channel: {} , the channel Name is not set.", channel.id));
            }
            else if (string.IsNullOrEmpty(channel.description))
            {
                throw new Exception(string.Format("Cannot register notification channel: {} , the channel Description is not set.", channel.id));
            }

            notificationManager.Call("registerNotificationChannel",
                                     channel.id,
                                     channel.title,
                                     Enum.IsDefined(typeof(Importance), channel.importance) ? channel.importance : (int)Importance.Default,
                                     channel.description,
                                     channel.enableLights,
                                     channel.enableVibration,
                                     channel.canBypassDnd,
                                     channel.canShowBadge,
                                     channel.VibrationPattern,
                                     Enum.IsDefined(typeof(LockScreenVisibility), channel.lockscreenVisibility) ? channel.lockscreenVisibility : (int)LockScreenVisibility.Public
                                     );
        }
Esempio n. 2
0
        /// <summary>
        /// Returns all notification channels that were created by the app.
        /// </summary>
        /// <returns>All existing channels</returns>
        public static AndroidNotificationChannel[] GetNotificationChannels()
        {
            if (!Initialize())
            {
                return(new AndroidNotificationChannel[0]);
            }

            var androidChannels = s_Jni.NotificationManager.GetNotificationChannels();
            var channels        = new AndroidNotificationChannel[androidChannels == null ? 0 : androidChannels.Length];

            for (int i = 0; i < channels.Length; ++i)
            {
                var channel = androidChannels[i];
                var ch      = new AndroidNotificationChannel();
                ch.Id                   = channel.Get <string>("id");
                ch.Name                 = channel.Get <string>("name");
                ch.Importance           = channel.Get <int>("importance").ToImportance();
                ch.Description          = channel.Get <string>("description");
                ch.EnableLights         = channel.Get <bool>("enableLights");
                ch.EnableVibration      = channel.Get <bool>("enableVibration");
                ch.CanBypassDnd         = channel.Get <bool>("canBypassDnd");
                ch.CanShowBadge         = channel.Get <bool>("canShowBadge");
                ch.VibrationPattern     = channel.Get <long[]>("vibrationPattern");
                ch.LockScreenVisibility = channel.Get <int>("lockscreenVisibility").ToLockScreenVisibility();

                channels[i] = ch;
            }

            return(channels);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns all notification channels that were created by the app.
        /// </summary>
        public static AndroidNotificationChannel[] GetNotificationChannels()
        {
            if (!Initialize())
            {
                return(new AndroidNotificationChannel[0]);
            }

            List <AndroidNotificationChannel> channels = new List <AndroidNotificationChannel>();

            var androidChannels = notificationManager.Call <AndroidJavaObject[]>("getNotificationChannels");

            foreach (var channel in androidChannels)
            {
                var ch = new AndroidNotificationChannel();
                ch.id         = channel.Get <string>("id");
                ch.title      = channel.Get <string>("name");
                ch.importance = channel.Get <int>("importance");

                ch.description = channel.Get <string>("description");

                ch.enableLights         = channel.Get <bool>("enableLights");
                ch.enableVibration      = channel.Get <bool>("enableVibration");
                ch.canBypassDnd         = channel.Get <bool>("canBypassDnd");
                ch.canShowBadge         = channel.Get <bool>("canShowBadge");
                ch.vibrationPattern     = channel.Get <long[]>("vibrationPattern");
                ch.lockscreenVisibility = channel.Get <int>("lockscreenVisibility");

                channels.Add(ch);
            }
            return(channels.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        ///  Creates a notification channel that notifications can be posted to.
        ///  Notification channel settings can be changed by users on devices running Android 8.0 and above.
        ///  On older Android versions settings set on the notification channel struct will still be applied to the notification
        ///  if they are supported to by the Android version the app is running on.
        /// </summary>
        /// <remarks>
        ///  When a channel is deleted and recreated, all of the previous settings are restored. In order to change any settings
        ///  besides the name or description an entirely new channel (with a different channel ID) must be created.
        /// </remarks>
        public static void RegisterNotificationChannel(AndroidNotificationChannel channel)
        {
            if (!Initialize())
            {
                return;
            }

            if (string.IsNullOrEmpty(channel.Id))
            {
                throw new Exception("Cannot register notification channel, the channel ID is not specified.");
            }
            if (string.IsNullOrEmpty(channel.Name))
            {
                throw new Exception(string.Format("Cannot register notification channel: {0} , the channel Name is not set.", channel.Id));
            }
            if (string.IsNullOrEmpty(channel.Description))
            {
                throw new Exception(string.Format("Cannot register notification channel: {0} , the channel Description is not set.", channel.Id));
            }

            s_NotificationManager.Call("registerNotificationChannel",
                                       channel.Id,
                                       channel.Name,
                                       (int)channel.Importance,
                                       channel.Description,
                                       channel.EnableLights,
                                       channel.EnableVibration,
                                       channel.CanBypassDnd,
                                       channel.CanShowBadge,
                                       channel.VibrationPattern,
                                       (int)channel.LockScreenVisibility
                                       );
        }
Esempio n. 5
0
 public void RegisterNotificationChannel(AndroidNotificationChannel channel)
 {
     self.Call("registerNotificationChannel",
               channel.Id,
               channel.Name,
               (int)channel.Importance,
               channel.Description,
               channel.EnableLights,
               channel.EnableVibration,
               channel.CanBypassDnd,
               channel.CanShowBadge,
               channel.VibrationPattern,
               (int)channel.LockScreenVisibility
               );
 }
Esempio n. 6
0
        /// <summary>
        ///  Creates a notification channel that notifications can be posted to.
        ///  Notification channel settings can be changed by users on devices running Android 8.0 and above.
        ///  On older Android versions settings set on the notification channel struct will still be applied to the notification
        ///  if they are supported to by the Android version the app is running on.
        /// </summary>
        /// <param name="channel">Channel parameters</param>
        /// <remarks>
        ///  When a channel is deleted and recreated, all of the previous settings are restored. In order to change any settings
        ///  besides the name or description an entirely new channel (with a different channel ID) must be created.
        /// </remarks>
        public static void RegisterNotificationChannel(AndroidNotificationChannel channel)
        {
            if (!Initialize())
            {
                return;
            }

            if (string.IsNullOrEmpty(channel.Id))
            {
                throw new Exception("Cannot register notification channel, the channel ID is not specified.");
            }
            if (string.IsNullOrEmpty(channel.Name))
            {
                throw new Exception(string.Format("Cannot register notification channel: {0} , the channel Name is not set.", channel.Id));
            }
            if (string.IsNullOrEmpty(channel.Description))
            {
                throw new Exception(string.Format("Cannot register notification channel: {0} , the channel Description is not set.", channel.Id));
            }

            s_Jni.NotificationManager.RegisterNotificationChannel(channel);
        }
Esempio n. 7
0
        /// <summary>
        /// Returns all notification channels that were created by the app.
        /// </summary>
        public static AndroidNotificationChannel[] GetNotificationChannels()
        {
            if (!Initialize())
            {
                return(new AndroidNotificationChannel[0]);
            }

            List <AndroidNotificationChannel> channels = new List <AndroidNotificationChannel>();

            var androidChannels = notificationManager.Call <AndroidJavaObject[]>("getNotificationChannels");

            foreach (var channel in androidChannels)
            {
                var ch = new AndroidNotificationChannel();
                ch.id         = channel.Get <string>("id");
                ch.title      = channel.Get <string>("name");
                ch.importance = channel.Get <int>("importance");

                ch.description = channel.Get <string>("description");

                ch.enableLights    = channel.Get <bool>("enableLights");
                ch.enableVibration = channel.Get <bool>("enableVibration");
                ch.canBypassDnd    = channel.Get <bool>("canBypassDnd");
                ch.canShowBadge    = channel.Get <bool>("canShowBadge");
                // There is an issue with IL2CPP failing to compile a struct which contains an array of long on Unity 2019.2+ (see case 1173310).
                var vibrationPattern = channel.Get <long[]>("vibrationPattern");
                if (vibrationPattern != null)
                {
                    ch.vibrationPattern = vibrationPattern.Select(i => (int)i).ToArray();
                }
                ch.lockscreenVisibility = channel.Get <int>("lockscreenVisibility");

                channels.Add(ch);
            }
            return(channels.ToArray());
        }