static PendingIntent CreateContentOrDeleteIntent(string action, IPlatformNotificationBuilder builder, ToastId toastId)
        {
            var intent = new Intent(action);

            toastId.ToIntent(intent);
            builder.AddCustomArgsTo(intent);

            var result = PendingIntent.GetBroadcast(Application.Context, toastId.GetPersistentHashCode(), intent, 0)
                         ?? throw new InvalidOperationException(ErrorStrings.KBroadcastError);

            return(result);
        }
            private void OnTapped(ToastId toastId, TaskCompletionSource <NotificationResult>?tcs)
            {
                var activity = hrIntentManager.Value.options.Activity;

                if (activity.IsDestroyed)
                {
                    try
                    {
                        var packageManager = Application.Context.PackageManager;
                        var intent         = packageManager?.GetLaunchIntentForPackage(hrIntentManager.Value.options.PackageName);
                        if (intent != null)
                        {
                            intent.AddCategory(Intent.CategoryLauncher);
                            toastId.ToIntent(intent);
                            Application.Context.StartActivity(intent);
                        }
                    }
                    catch (Exception ex)
                    {
                        hrIntentManager.Value.logger?.LogError(ex, "can't start application activity");
                    }
                }
                else if (activity.HasWindowFocus == false)
                {
                    try
                    {
                        var intent = new Intent(activity, activity.GetType());
                        toastId.ToIntent(intent);
                        intent.SetFlags(ActivityFlags.ReorderToFront);
                        activity.StartActivityIfNeeded(intent, 0);
                    }
                    catch (Exception ex)
                    {
                        hrIntentManager.Value.logger?.LogError(ex, "can't reorder to front an application activity");
                    }
                }
                tcs?.TrySetResult(NotificationResult.Activated);
                hrIntentManager.Value.systemEventSource.SendEvent(new NotificationEvent(toastId));
            }
        public PendingIntent RegisterToShowWithDelay(IPlatformNotificationBuilder builder, ToastId toastId)
        {
            if (builder.UsingCustomContentIntent == false)
            {
                SetContentIntent(builder, toastId);
            }

            var notification = builder.Build();
            var intent       = new Intent(IntentConstants.KScheduled);

            toastId.ToIntent(intent);
            intent.PutExtra(IntentConstants.KNotification, notification);
            var pendingIntent = PendingIntent.GetBroadcast(Application.Context, toastId.GetPersistentHashCode(), intent, PendingIntentFlags.CancelCurrent)
                                ?? throw new InvalidOperationException(ErrorStrings.KBroadcastError);

            return(pendingIntent);
        }
        PendingIntent CreateLaunchIntent(IPlatformNotificationBuilder builder, ToastId toastId)
        {
            var packageManager = Application.Context.PackageManager;
            var intent         = packageManager?.GetLaunchIntentForPackage(options.PackageName);

            if (intent == null)
            {
                throw new InvalidOperationException("can't get launch intent");
            }
            intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
            toastId.ToIntent(intent);
            builder.AddCustomArgsTo(intent);
            var result = PendingIntent.GetActivity(Application.Context, toastId.GetPersistentHashCode(), intent, PendingIntentFlags.UpdateCurrent)
                         ?? throw new InvalidOperationException(ErrorStrings.KBroadcastError);

            return(result);
        }