Xamarin表单中的通知点击事件 [英] Notification click event in xamarin forms

查看:183
本文介绍了Xamarin表单中的通知点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户单击Notification时打开xaml页面.我已经搜索过,但找不到适合这种情况的样本. 顺便说一下,我将FCM与旧的GCM集成使用.如何在android中实现呢?

I want to open an xaml page when user clicks on the Notification. I've searched but cant find a decent sample for this situation. By the way I'm using FCM with old GCM integration.How can I achieve this in android ?

推荐答案

当用户单击通知时,我想打开一个xaml页面.

I want to open an xaml page when user clicks on the notification .

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

When you receive a Notification from FCM, you could add a PendingIntent in Notification to implement this function, this will allow the user to open the app. Code like this :

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());
    }

有关更多信息,您可以阅读此处是完整的代码.

For more information, you could read the document and here is the complete code.

这篇关于Xamarin表单中的通知点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆