The application implements sending push messages using the Firebase Messaging Service . Tell me how to get these notifications without clicking on the notification itself. I know how to get data when I click on a notification or when the application is in the Foreground. I wonder when the app is in the background.

  • Look 2 way in the answer here: ru.stackoverflow.com/a/607320/17609 - Yuriy SPb
  • @Yuriy SPb, my message contains 2 types to be processed both in the background and in the foreground. When the notification came and I open the application, I don’t see anything in Extras; if I open it by clicking on the notification, then everything is OK. - Ivan Vovk
  • The last time I fumbled with this about a year ago and came to the conclusion in order to process only in one way - manually. Those. send everything in data and manually generate notifications and display - then everything works and there is no difference in behavior regardless of the application state. - YurySPb

1 answer 1

The application should have a class derived from FirebaseMessagingService in which you override the onMessageReceived method. This method enters the RemoteMessage object from which you take out the information.

 public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { //этот метод отрабатывает всегда когда заходит push } } 

Do not forget to register in the manifest

 <service android:name=".fcm.MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service>