EDIT3: Ok I found the problem : If the app is killed, sending both data
and notification
won't trigger onMessageReceived
. notification
needs to be set to null if the target device is android.
That's really a dumb behaviour.
Original post:
I can successfully retrieve the bundle from the intent passed by the notificationBuilder
to the activity when the app is launched.
However, if I kill the app, the notification still works but the GetExtras()
from the intent is null.
In my FirebaseMessagingService
child class:
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("key_1","value");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//also tried with PendingIntent.FLAG_CANCEL_CURRENT
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("title")
.setContentText("messageBody")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
When the app is killed, the firebaseMessagingService
can't even write a file. It does not crash, it builds, and shows the notification, but anything done to the disk does not work.
EDIT: I have replaced the content of the onMessageReceived
method as follows:
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
// Do nothing
}
When the app is running nothing happens -as expected- but when the app is killed a notification is displayed whith the name app as a title and remoteMessage.getNotification().getBody()
as content text.
It seems that onMessageReceived
is not fired. Instead another magic function is called...
EDIT2: As requested, this is what is sent from the server:
{
"data":
{
"form_id":"33882606580812",
"recipientUserId":10500
}
,
"to":"e0bU2jIVO9g:APA91bHsS-s3G1gQLcTFtRUC77pJUWcZvD7h9NfUgFLD-bFam1S0dddngVcmrQlXR5i6DfTsc69T8JbIrSuzyF1iv0c4ac1gmkwvGVMwZo_yA4KwOh82Nx-weYeL79r79si4qH3QBEgs",
"notification":
{
"body":"you have a new notification",
"badge":"1",
"sound":"default"
},
"delay_while_idle":false
}