/// <summary>
        /// Create Notification Channel Group when API >= 26.
        /// If you'd like to further organize the appearance of your channels in the settings UI, you can create channel groups.
        /// This is a good idea when your app supports multiple user accounts (such as for work profiles),
        /// so you can create a notification channel group for each account.
        /// This way, users can easily identify and control multiple notification channels that have identical names.
        /// </summary>
        /// <param name="request"></param>
        public static void CreateNotificationChannelGroup(NotificationChannelGroupRequest request)
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return;
            }

            if (!(Application.Context.GetSystemService(Context.NotificationService) is NotificationManager
                  notificationManager))
            {
                return;
            }

            if (request is null ||
                string.IsNullOrWhiteSpace(request.Group) ||
                string.IsNullOrWhiteSpace(request.Name))
            {
                return;
            }

            using (var channelGroup = new NotificationChannelGroup(request.Group, request.Name))
            {
                notificationManager.CreateNotificationChannelGroup(channelGroup);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Notification Channel Group when API >= 26.
        /// If you'd like to further organize the appearance of your channels in the settings UI, you can create channel groups.
        /// This is a good idea when your app supports multiple user accounts (such as for work profiles),
        /// so you can create a notification channel group for each account.
        /// This way, users can easily identify and control multiple notification channels that have identical names.
        /// </summary>
        /// <param name="request"></param>
        public static bool CreateNotificationChannelGroup(NotificationChannelGroupRequest request = null)
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return(false);
            }

            if (!(Application.Context.GetSystemService(Context.NotificationService) is NotificationManager
                  notificationManager))
            {
                return(false);
            }

            request ??= new NotificationChannelGroupRequest();

            if (string.IsNullOrWhiteSpace(request.Group))
            {
                request.Group = AndroidOptions.DefaultGroupId;
            }

            if (string.IsNullOrWhiteSpace(request.Name))
            {
                request.Name = AndroidOptions.DefaultGroupName;
            }

            using var channelGroup = new NotificationChannelGroup(request.Group, request.Name);
            notificationManager.CreateNotificationChannelGroup(channelGroup);
            return(true);
        }
        public void CreateNotificationChannel()
        {
            if (NotificationChannelsApiCheck())
            {
                return;
            }

            var group = new NotificationChannelGroup(_groupIdInputField.text, RandomName())
            {
                Description = "Android-Goodies test notification channel group"
            };

            AGNotificationManager.CreateNotificationChannelGroup(group);

            var channel = NewNotificationChannel(_channelIdInputField.text, RandomName(), group.Id);

            channel.ShowBadge = true;
            AGNotificationManager.CreateNotificationChannel(channel);

            var retrievedChannel = AGNotificationManager.GetNotificationChannel(channel.Id);
            var retrievedGroup   = AGNotificationManager.GetNotificationChannelGroup(group.Id);

            var msg = "Channel created: " + retrievedChannel + ", with group: " + retrievedGroup;

            Debug.Log(msg);
            _resultText.text = msg;

            _lastChannelId = channel.Id;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a Notification Channel Group
 /// Afterwards you can set this group to a notification channel with SetGroup(groupId) prior to it's registration in NotificationManager
 /// </summary>
 /// <param name="groupId">Id for the group</param>
 /// <param name="groupName">Name for the group (should be localized)</param>
 /// <param name="description">Optional parameter to specify Description for this group</param>
 public static void CreateNotificationChannelGroup(string groupId, string groupName, string?description = null)
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
     {
         var group = new NotificationChannelGroup(groupId, groupName);
         if (description != null)
         {
             group.Description = description;
         }
         NotificationManager.FromContext(Application.Context).CreateNotificationChannelGroup(group);
     }
 }
Exemplo n.º 5
0
    void CreateNotificationChannel()
    {
        manager = (NotificationManager)AndroidApp.Context.GetSystemService(AndroidApp.NotificationService);

        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            NotificationChannelGroup group = new NotificationChannelGroup("NEWMSGL", "New Message");
            manager.CreateNotificationChannelGroup(group);

            var channelNameJava = new Java.Lang.String(channelName);
            var channel         = new NotificationChannel(channelId, channelNameJava, NotificationImportance.High)
            {
                Description = channelDescription,
                Group       = "NEWMSGL"
            };
            manager.CreateNotificationChannel(channel);
        }

        channelInitialized = true;
    }
        public void CreateNotificationChannelGroup()
        {
            if (NotificationChannelsApiCheck())
            {
                return;
            }

            var group = new NotificationChannelGroup(_groupIdInputField.text, RandomName())
            {
                Description = "Android-Goodies test notification channel group"
            };

            AGNotificationManager.CreateNotificationChannelGroup(group);

            var channelGroup = AGNotificationManager.GetNotificationChannelGroup(group.Id);

            Debug.Log("Channel group: " + channelGroup);

            _lastGroupId = group.Id;
        }
        private static async Task ActuallyInitializeChannelsAsync(NotificationManager notificationManager)
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return;
            }

            var accounts = await AccountsManager.GetAllAccounts();

            var groups = notificationManager.NotificationChannelGroups;

            // Delete groups which the account was deleted
            foreach (var g in groups)
            {
                if (!accounts.Any(a => a.LocalAccountId.ToString() == g.Id))
                {
                    notificationManager.DeleteNotificationChannelGroup(g.Id);
                }
            }

            // Add/update groups
            foreach (var a in accounts)
            {
                var g = groups.FirstOrDefault(i => i.Id == a.LocalAccountId.ToString());
                if (g != null)
                {
                    // If details are already correct
                    if (g.Name == a.Username)
                    {
                        // Do nothing
                        continue;
                    }
                }

                // Otherwise need to create (or update) group
                g = new NotificationChannelGroup(a.LocalAccountId.ToString(), a.Username);
                notificationManager.CreateNotificationChannelGroup(g);
            }

            // Update/create channels
            foreach (var a in accounts)
            {
                var channelDayBefore = new NotificationChannel(GetChannelIdForDayBefore(a.LocalAccountId), "Day before reminders", NotificationImportance.High)
                {
                    Description          = "Daily reminders that tell you what incomplete tasks or events you have coming up tomorrow.",
                    Group                = a.LocalAccountId.ToString(),
                    LightColor           = new Color(55, 84, 198), // #3754C6 (a bit more vibrant than my other theme colors)
                    LockscreenVisibility = NotificationVisibility.Public
                };
                channelDayBefore.SetShowBadge(true);
                channelDayBefore.EnableVibration(true);
                notificationManager.CreateNotificationChannel(channelDayBefore);

                var channelDayOf = new NotificationChannel(GetChannelIdForDayOf(a.LocalAccountId), "Day of reminders", NotificationImportance.High)
                {
                    Description          = "Reminders that appear an hour before an incomplete task or event is due.",
                    Group                = a.LocalAccountId.ToString(),
                    LightColor           = new Color(55, 84, 198), // #3754C6 (a bit more vibrant than my other theme colors)
                    LockscreenVisibility = NotificationVisibility.Public
                };
                channelDayOf.SetShowBadge(true);
                channelDayOf.EnableVibration(true);
                notificationManager.CreateNotificationChannel(channelDayOf);
            }
        }