【问题标题】:Notification click event in xamarin forms [closed]xamarin 表单中的通知单击事件[关闭]
【发布时间】:2017-12-25 16:31:05
【问题描述】:

当用户点击Notification 时,我想打开一个xaml 页面。我已经搜索过,但找不到适合这种情况的合适样本。 顺便说一句,我正在使用 FCM 和旧的 GCM 集成。如何在 android 中实现这一点?

【问题讨论】:

    标签: push-notification xamarin.android xamarin.forms firebase-cloud-messaging


    【解决方案1】:

    我想在用户点击通知时打开一个 xaml 页面。

    当您收到来自FCMNotification 时,您可以在Notification 中添加PendingIntent 来实现此功能,这将允许用户打开应用程序。像这样的代码:

    void SendNotification(string messageBody)
    {
       var intent = new Intent(this, typeof(MainActivity));
            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
    
            var notificationBuilder = new Notification.Builder(this)
                .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
                .SetContentTitle("FCM Message")
                .SetContentText(messageBody)
                .SetAutoCancel(true)
                .SetContentIntent(pendingIntent);
    
            var notificationManager = NotificationManager.FromContext(this);
            notificationManager.Notify(0, notificationBuilder.Build());
        }
    

    有关更多信息,您可以阅读documenthere 是完整代码。

    【讨论】:

    • 谢谢,我已经这样做了,但我的问题是我想打开一个不同的 xaml 页面。你的建议是只打开应用程序,我的意思是主页。
    猜你喜欢
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多