Как открыть приложение в уведомлении нажмите, пока закрыто - PullRequest
0 голосов
/ 30 сентября 2019

Я пытался открыть приложение, когда вы нажимаете на него, когда оно закрыто, я получаю уведомления FCM, даже если приложение закрыто, но когда я нажимаю на него, ничего не происходит. Если приложение работает или работает в фоновом режиме, оно реагирует так, как задумано.

Я использую Xamarin Forms, и в 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();
            }

Ожидается, что приложение откроется, если оно закрыто, но я так и не получил его, спасибо за помощь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...