Forum Xamarin.Forms

How to open a different xaml page on push notification click event?

slayer35slayer35 USMember

Hello,I want to open a different xaml page from android push notification click? But I have searched the forum and internet but cant find a working solution.Any ideas about how to achive this? (I'm using fcm integration in xamarin.forms project)


  • slayer35slayer35 USMember

    Thank you very much,This work well for me too.Thats just I need.

  • ArvindrajaArvindraja INMember ✭✭✭
    edited December 2017


    As you are showing/writing navigation in else block of UIApplicationState.Active , I wonder how it going to work, why because notifications tap events firing somewhere else.
    I am using Xamarin.iOS, and notification tap event here firing.

     public class CustomUNUserNotificationCenterDelegate : UNUserNotificationCenterDelegate
            public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
             **   // Here you handle the user taps**
            public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
                completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Badge);

    However I am getting notifications data here. but I dont have idea to navigate to specific page.
    Please suggest me if you people have better idea.

    Thank you

  • SnerfSnerf CAMember

    So I want to have a notification open a new page, so the user can view the full message.
    It works great with Xamarin.Android, you use the Notification.Builder(), and start a new Intent. voila

    But with Xamarin.iOS, if the app is open , I have no luck.
    Trying App.Current.MainPage.Navigation.PushModalAsync(new MyPage()) and it does nothing , it just stays at the current screen on the app

    Any ideas?

  • BasilJohnBasilJohn NZMember ✭✭

    @VenkataSwamy, thanks for your solution. It works well.
    Did you ever do saving the push notification in a local database?

  • ArmaganCelikArmaganCelik USMember ✭✭

    __in android side you can use this way_

    first in MainActivity
    LaunchMode = LaunchMode.SingleTop_

    and than_

    protected override void OnNewIntent(Intent intent)
    if (intent != null)
    string NotificationId = Intent.GetStringExtra("NotificationId");
    if (NotificationId != null)
    App.IsNotified = true;
    App.NotifiedId = NotificationId;

                    Page currentPage = App.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
                    var content = currentPage.FindByName<ContentView>("cvContentPlaceHolder");
                    var notificationsSegmentedBarPage = new NotificationsSegmentedBarPage(Convert.ToInt32(App.NotifiedId));
                    content.Content = notificationsSegmentedBarPage.Content;
  • DeepakDYDeepakDY INMember ✭✭✭
    edited January 2019

    Hello @VenkataSwamy , @BasilJohn

    How can get notification id and job id

  • MouniMouni Member

    @VenkataSwamy ,I've got the error "**android.content.Context.getPackageName()' on a null object reference
    **" at the line var intent = new Intent(this, typeof(MainActivity));,Can you please help me

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited March 2019

    Hi @VenkataSwamy I am trying to open a content page when taps the notification.

    What is AppGcmListenerService.cs? Is that invoke when we tap a notification? What are jobId and NotificationId? Is this work with FCM?

    Can you help me to complete this implementation? I have started a new thread for this.

Sign In or Register to comment.