question

BahaMasoud-0939 avatar image
0 Votes"
BahaMasoud-0939 asked ·

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

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
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for reaching here! Could you please share the document/article you are following to help you better on this.

0 Votes 0 ·
BahaMasoud-0939 avatar image
0 Votes"
BahaMasoud-0939 answered ·

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.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GauravKhanna avatar image
0 Votes"
GauravKhanna answered ·

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


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BahaMasoud-0939 avatar image
0 Votes"
BahaMasoud-0939 answered ·

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?

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SnehaAgrawal-MSFT avatar image
0 Votes"
SnehaAgrawal-MSFT answered ·

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
















· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.