How to use xamarin push notification to specific page in the app?

Baha Masoud 41 Reputation points
2020-11-26T02:22:27.79+00:00

I could not find anything or was outdated on when the app is in the background or not running, the user clicks the notification icon, and will be directed to a specific page inside the app (every time the page might be different), i am not sure where to look, is it the template that needed to be modified or additional code?

thanks for any tips.

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
257 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Baha Masoud 41 Reputation points
    2020-11-26T08:07:44.727+00:00

    Currently, my Xamarin app is working fine receiving notifications. but the main page is always opening when I click the notification from the background.
    and like i said, i could not find any code in xamarin forum regarding adding a link with the notification except for a question from a few years ago (does not work anymore):

    https://forums.xamarin.com/discussion/40352/how-to-go-to-specific-page-when-user-clicks-on-push-notification

    regards.


  2. Gaurav Khanna 6 Reputation points
    2020-11-26T08:26:35.907+00:00

    As main page is getting opened when you click on notification, you can add code in your main page to navigate to the page of your choice when you receive message/notification.

    Following link has nice explanation with steps

    azure-notification-hub

    0 comments No comments

  3. Baha Masoud 41 Reputation points
    2020-11-26T08:51:47.387+00:00

    Do you mean that the message body in the notifications should include the link, and when I call:
    messageBody = message.Data.Values.First();

    then somehow I need to separate the notification text from the link?

    0 comments No comments

  4. SnehaAgrawal-MSFT 18,191 Reputation points
    2020-11-27T10:09:29.93+00:00

    Thanks for reply. As mentioned in the document when Configuring the Android application for notifications in Override FirebaseMessagingService to handle messages

    The Incoming messages are converted to a local notification with the SendLocalNotification method. This method creates a new Intent and places the message content into the Intent as a string Extra. When the user taps the local notification, whether the app is in the foreground or the background, the MainActivity is launched and has access to the message contents through the Intent object. This also sends the message directly to the current MainPage instance with the SendMessageToMainPage method.

    If you want to redirect to a specific page when the app is opened try overriding OnNewIntent method in MainActivity class and navigation

    Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new Views.AboutPage());

    Refer to below discussion links might be helpful:

    https://forums.xamarin.com/discussion/176711/redirect-to-specific-page-when-firebase-notification-tapped

    https://forums.xamarin.com/discussion/152168/open-specific-page-when-click-on-push-notification

    0 comments No comments