androidfirebasefirebase-notifications

How can I open a url when click on push notification, when app is closed, sent by Firebase?


I receive notifications when the app is closed and when it's open, but when it's closed and I click on the push notification that has a link it only opens the app and doesn't open the browser, and if the app is open and I click on the push notification the browser opens.

How can I open the browser when I click on a push notification that has a URL and when the app is closed.


Solution

  • An FCM with notification payload does not go through the onMessageReceived when your app is not running. It's posted by Google Play Services on your behalf directly to notification shade. Once clicked your main activity is launched and intent extras contain the data payload.

    You have two options:

    1. Continue using notification payload and handle the data in your main activity onCreate.

    That's the activity started by launcher. Use this for information push notifications. If your app is not running it won't be started, which saves battery.

    1. Don't use notification payload.

    Use this for business logic push messages. This will always start your app process and let you handle the message in onMessageReceived.

    Read more here: