C# 关闭时如何在通知中打开应用程序单击

C# 关闭时如何在通知中打开应用程序单击,c#,android,forms,xamarin,C#,Android,Forms,Xamarin,我一直在尝试打开应用程序,当你在应用程序关闭时单击它,即使应用程序关闭,我也会收到FCM通知,但当我单击它时,什么也没有发生。如果应用程序正在运行或处于后台,它将按预期响应 我正在运行Xamarin表单,在Android中,我不知道关闭应用程序时会发生什么,因为我没有调试 //SendNotifications public void SendNotification(string body) { using (var notificationManager = NotificationMan

我一直在尝试打开应用程序,当你在应用程序关闭时单击它,即使应用程序关闭,我也会收到FCM通知,但当我单击它时,什么也没有发生。如果应用程序正在运行或处于后台,它将按预期响应

我正在运行Xamarin表单,在Android中,我不知道关闭应用程序时会发生什么,因为我没有调试

//SendNotifications
public void SendNotification(string body)
{

using (var notificationManager = NotificationManager.FromContext(BaseContext))
{
                var intent = new Intent(this, typeof(MainActivity));
                intent.AddFlags(ActivityFlags.ClearTop);
                intent.PutExtra("SomeSpecialKey", "some special value");
                var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
// sends notification to view model
                MessagingCenter.Send((App)Xamarin.Forms.Application.Current, "Increase");

                //PendingIntent pendingIntent = PendingIntent.GetActivity(this.ApplicationContext, 0, intent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.OneShot);
                Notification notification;
                if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O)
                {

                    notification = new Notification.Builder(BaseContext)
                                                                .SetContentTitle("Notification")
                                                                .SetContentText(body)
                                                                .SetAutoCancel(true)
                                                                .SetSmallIcon(Resource.Drawable.icon)
                                                                .SetDefaults(NotificationDefaults.All)
                                                                .SetContentIntent(pendingIntent)
                                                                .Build();

                }
                else
                {
                    var myUrgentChannel = BaseContext.PackageName;
                    const string channelName = "CanalComun";

                    NotificationChannel channel;
                    channel = notificationManager.GetNotificationChannel(myUrgentChannel);
                    if (channel == null)
                    {
                        channel = new NotificationChannel(myUrgentChannel, channelName, NotificationImportance.High);
                        channel.EnableVibration(true);
                        channel.EnableLights(true);
                        channel.SetSound(
                            RingtoneManager.GetDefaultUri(RingtoneType.Notification),
                            new AudioAttributes.Builder().SetUsage(AudioUsageKind.Notification).Build()
                        );
                        channel.LockscreenVisibility = NotificationVisibility.Public;
                        notificationManager.CreateNotificationChannel(channel);
                    }
                    channel?.Dispose();

                    notification = new Notification.Builder(BaseContext)
                                                                .SetChannelId(myUrgentChannel)
                                                                .SetContentTitle("Notification")
                                                                .SetContentText(body)
                                                                .SetAutoCancel(true)
                                                                .SetSmallIcon(Resource.Drawable.icon)
                                                                .SetContentIntent(pendingIntent)
                                                                .Build();
                }
                notificationManager.Notify(1331, notification);
                notification.Dispose();
            }
//发送通知
公共void SendNotification(字符串体)
{
使用(var notificationManager=notificationManager.FromContext(BaseContext))
{
var intent=新的intent(此,类型为(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
intent.PutExtra(“某些特殊值”、“某些特殊值”);
var pendingIntent=pendingIntent.GetActivity(this,0,intent,PendingIntentFlags.OneShot);
//向视图模型发送通知
MessagingCenter.Send((App)Xamarin.Forms.Application.Current,“增加”);
//PendingEvent PendingEvent=PendingEvent.GetActivity(this.ApplicationContext,0,intent,PendingEventFlags.UpdateCurrent | PendingEventFlags.OneShot);
通知;
if(Android.OS.Build.VERSION.SdkInt

如果关闭,则应打开应用程序,但我从未让它工作,感谢您的帮助

如果您使用Plugin.FirebasePushNotification,则可以挂接CrossFirebasePushNotification.Current.OnNotificationOpened+=(s,p)=>{};在App.cs中根据您的代码,当应用程序关闭时,我无法收到通知。请您共享一个基本演示,以便我们使用它进行测试,好吗?