1

I have created a chat application using Firebase.

How to go to a particular chat activity, when clicked on a notification with message data?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • when using firebase, usually the node is basically your chat, so try naming it uniquely and when ever you throw msg the id must be sent along with other json attritbutes and then on click you can easily navigate towards that id. – Awais Tariq Oct 16 '18 at 11:44

2 Answers2

0

In your manifest file, you should declare the below intent filter for the activity that needs to be launched when an FCM notification is clicked :

<intent-filter>
       <action android:name="NEW_MESSAGE" />

       <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

And in your activity that launches when them notification is clicked, you can receive the data from the notification using bundle as below:

Bundle extras = notificationIntent.getExtras();
0

There are two types of FCM messages: Notification and Data. The simple messages sent from the Firebase console are of type Notification. This means that when receiving the message in the background you can't control which Activity to open. BUT when receiving the message in the foreground OR sending a Data message (sent from the Cloud Functions or your app server), you can catch the message on onMessageReceived and create your own notification.

enter image description here

link to Firebase about receiving messages : Receive Messages in an Android App

link to Firebase about FCM messages : About FCM Messages

link about starting an Activity from a Notification : Start an Activity from a Notification

Hadas
  • 906
  • 12
  • 22