I find the firebase doc about this subject too elusive: https://firebase.google.com/docs/cloud-messaging/android/receive#backgrounded
I've followed this answer : https://stackoverflow.com/a/47392189/2068732and and I'm able to catch a notification received when the app is in background.
However, it is not satisfactory because the WakefulBroadcastReceiver class is deprecated.
What is the proper way to forward the notification to the MyFirebaseMessagingService's onMessageReceived() method ?
Here is my MyFirebaseMessagingService class:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(getClass().getName(), "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(getClass().getName(), "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(getClass().getName(), "Message Notification Body: " + remoteMessage.getNotification().getBody());
displayNotification(remoteMessage);
}
}
}
and manifest:
<service
android:name=".firebase.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>