点击Xamarin Forms中的本地通知时如何重定向到页面?

时间:2018-07-16 17:15:42

标签: xamarin xamarin.forms xamarin.android prism

我正在使用Xamarin Forms和Prism开发一个应用程序,并且正在使用本地API发送本地通知。用户点击通知后如何在特定页面中打开我的应用程序?

这是我的发送本地通知的Android代码:

 public static class NotificacoesUtil
    {
        public static void GeraNotificacao(Context context, Intent intent, string ticker, string titulo, string descricao)
        {
            var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            var pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0);

            var builderNotification = new NotificationCompat.Builder(context);

            builderNotification.SetTicker(ticker);
            builderNotification.SetContentTitle(titulo);
            builderNotification.SetContentText(descricao);
            builderNotification.SetSmallIcon(Resource.Drawable.ic_notification);
            builderNotification.SetColor(ContextCompat.GetColor(context, Resource.Color.colorNotification));
            builderNotification.SetContentIntent(pendingIntent);

            var notification = builderNotification.Build();
            notification.Vibrate = new long[] { 0, 400, 200, 400 };
            notification.Flags = NotificationFlags.AutoCancel;

            notificationManager.Notify(Resource.Mipmap.ic_launcher, notification);

            try
            {
                var som = RingtoneManager.GetActualDefaultRingtoneUri(context, RingtoneType.Notification);
                var toque = RingtoneManager.GetRingtone(context, som);
                toque.Play();
            }
            catch (System.Exception e)
            {
                Log.Error("OdontoWayPaciente_MensagemErro", e.Message);
                Log.Error("OdontoWayPaciente_StackTrace", e.StackTrace);
            }
        }
    }

这是我注册导航类型的方法:

protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<NavigationPage>();
            containerRegistry.RegisterForNavigation<Login>();
            containerRegistry.RegisterForNavigation<Pacientes>();
            containerRegistry.RegisterForNavigation<Clinicas>();
            containerRegistry.RegisterForNavigation<PacienteEdit>();
            containerRegistry.RegisterForNavigation<ClinicaMap>();
            containerRegistry.RegisterForNavigation<LinkWeb>();
            containerRegistry.RegisterForNavigation<Sobre>();
            containerRegistry.RegisterForNavigation<Views.Android.PacienteAcessos, PacienteAcessosViewModel>("Android.PacienteAcessos");
            containerRegistry.RegisterForNavigation<Views.iOS.PacienteAcessos, PacienteAcessosViewModel>("iOS.PacienteAcessos");
            containerRegistry.RegisterForNavigation<Views.Android.Main, MainViewModel>("Android.Main");
            containerRegistry.RegisterForNavigation<Views.iOS.Main, MainViewModel>("iOS.Main");
            containerRegistry.RegisterForNavigation<CadastroUsuario>();
            containerRegistry.RegisterForNavigation<Perfil>();
            containerRegistry.RegisterForNavigation<NomeUsuarioEdit>();
            containerRegistry.RegisterForNavigation<AlteracaoSenha>();
            containerRegistry.RegisterForNavigation<RecuperacaoSenha>();
        }

当用户点击通知时,我要打开Pacientes页面。这时,当我点击通知时,该应用程序无法打开并且什么也不做。

0 个答案:

没有答案