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.
1 answer
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> |
dataand manually generate notifications and display - then everything works and there is no difference in behavior regardless of the application state. - YurySPb ♦