Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How open Url after Firebase message received in background

When application is in background and Firebase message received I want to open specific url that is in message data. For example i put below key-value in Firebase and i want to open google site after user tap on notification.

key: url
value: http://google.com

what should i do? tnx in advance!

like image 220
Ahmad Vatani Avatar asked Jun 05 '16 11:06

Ahmad Vatani


People also ask

How do you handle notifications when an app is in foreground in Firebase?

Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you'll need to write code to handle the onMessageReceived callback.

How does Firebase integrate with push notifications on a website?

Open the Cloud Messaging tab of the Firebase console Settings pane and scroll to the Web configuration section. In the Web Push certificates tab, find and select the link text, "import an existing key pair."


1 Answers

In your application you can access the key/value pairs sent from Advanced options > Custom data in the Firebase Notification Web console in these ways:

  • getIntent().getExtras() in the activity that is launched when the user tap the notification.
    I recommend to add this in the activity onResume() method.
  • remoteMessage.getData() in FirebaseMessagingService.onMessageReceived() if the application is already open when the message arrives. (in this case the notification is not shown and instead the onMessageReceived() is invoked.
like image 138
Diego Giorgini Avatar answered Oct 04 '22 02:10

Diego Giorgini