Example #1
0
        public static void AssertValid(this ChannelAction action)
        {
            if (action.Identifier.IsEmpty())
            {
                throw new ArgumentException("ChannelAction Identifier is required", nameof(action.Identifier));
            }

            if (action.Title.IsEmpty())
            {
                throw new ArgumentException("ChannelAction Title is required", nameof(action.Title));
            }
        }
        protected virtual NotificationCompat.Action CreateTextReply(Notification notification, ChannelAction action)
        {
            var pendingIntent = this.CreateActionIntent(notification, action);
            var input         = new AndroidX.Core.App.RemoteInput.Builder(AndroidNotificationProcessor.RemoteInputResultKey)
                                .SetLabel(action.Title)
                                .Build();

            var iconId       = this.core.Android.GetResourceIdByName(action.Identifier);
            var nativeAction = new NotificationCompat.Action.Builder(iconId, action.Title, pendingIntent)
                               .SetAllowGeneratedReplies(true)
                               .AddRemoteInput(input)
                               .Build();

            return(nativeAction);
        }
        protected virtual NotificationCompat.Action CreateAction(Notification notification, ChannelAction action)
        {
            var pendingIntent = this.CreateActionIntent(notification, action);
            var iconId        = this.core.Android.GetResourceIdByName(action.Identifier);
            var nativeAction  = new NotificationCompat.Action.Builder(iconId, action.Title, pendingIntent).Build();

            return(nativeAction);
        }
        protected virtual PendingIntent CreateActionIntent(Notification notification, ChannelAction action)
        {
            var intent  = this.core.Android.CreateIntent <ShinyNotificationBroadcastReceiver>(ShinyNotificationBroadcastReceiver.EntryIntentAction);
            var content = this.core.Serializer.Serialize(notification);

            intent
            .PutExtra(AndroidNotificationProcessor.IntentNotificationKey, content)
            .PutExtra(AndroidNotificationProcessor.IntentActionKey, action.Identifier);

            counter++;
            var pendingIntent = PendingIntent.GetBroadcast(
                this.core.Android.AppContext,
                counter,
                intent,
                PendingIntentFlags.UpdateCurrent
                ) !;

            return(pendingIntent);
        }