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 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I want to open an xaml page when user clicks on the notification .
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.