1
I implemented the notification service in my app, working, even receives notification in the background, however I wanted to save the notification message, searched a little and created a service ( code below ) works, but only when the app is open ( in the foreground ), background does not work.
public class FirebaseNotificationService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i("PVL", "Mensagem Recebida");
if (remoteMessage.getNotification().getBody() != null) {
Log.i("PVL", "Mensagem recebida: " + remoteMessage.getNotification().getBody());
} else {
Log.i("PVL", "Mensagem recebida: " + remoteMessage.getData().get("message"));
}
}
}
Do you want to save the notification message where? On mobile?
– viana
You can pass data beyond the notification through the FCM, so in principle, you don’t have to capture the notification itself, just pass the message as a notification data and read the received data in the app. Have a look: https://firebase.google.com/docs/cloud-messaging/concept-options?hl=pt-br
– Márcio Oliveira
@acklay at first I want to save in a list, to later display in a listview, make a history of received notifications
– Igor Oliveira