本文介绍了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 ?
推荐答案
当您从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表单中的通知点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!