0

我想在用戶點擊Notification時打開xaml頁面。我已經搜索過,但無法找到適合這種情況的體面樣本。 順便說一句,我正在使用FCM與舊GCM integration.How我可以在android中實現這一點?xamarin表單中的通知點擊事件

回答

1

我想在用戶點擊通知時打開一個xaml頁面。

當您收到NotificationFCM,你可以在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是完整的代碼。

+0

謝謝,我已經這樣做了,但我的問題是我想打開一個不同的xaml pages.Your建議只打開應用程序,我的意思是主頁。 – slayer35