quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

I receive only last one message when turn on internet?

Open Xing1P opened this issue 6 years ago • 36 comments

send with notification payload for background notification. but if send without "notification" payload i receive notification is normal when send while device off internet and then device turn on internet. https://fcm.googleapis.com/fcm/send

{
	"to":"....",
	"data":{
		"destination":"1",
		"source":"2",
		"badge":"1"},
	"notification":{
			"title":"Hello7","body":"Hello Test"
		},
	"priority":"high"
}

Step 1: Describe your environment

  • Android device: test on Pixel 2xl,Oneplus6,Oppo F7
  • Android OS version: Android 10,9,8
  • Google Play Services version: Last
  • Firebase/Play Services SDK version: Last

Step 2: Describe the problem:

Steps to reproduce:

  1. Turn off internet
  2. send fcm message 10
  3. Turn on internet
  4. Receive only last one message and 9 message not receive Note**: but when send notification while device online notification receive normal

Observed Results:

2019-12-03 14:03:47.765 4931-4931/? V/FA-SVC: NetworkBroadcastReceiver received action: android.net.conn.CONNECTIVITY_CHANGE 2019-12-03 14:03:47.801 4931-15302/? V/FA-SVC: Unregistering connectivity change receiver 2019-12-03 14:03:47.802 4931-15302/? V/FA-SVC: Upload scheduled in approximately ms: 3047916 2019-12-03 14:03:47.802 4931-15302/? V/FA-SVC: Cancelling job. JobID: 812057698 2019-12-03 14:03:47.811 4931-15302/? V/FA-SVC: Scheduling upload with GcmTaskService 2019-12-03 14:03:47.811 4931-15302/? V/FA-SVC: Scheduling task with Gcm. time: 3047916 2019-12-03 14:03:48.216 10173-15301/com.tss.testfcmraw D/FA: Logging event (FE): notification_receive(_nr), Bundle[{ga_event_origin(_o)=fcm, message_type(_nmc)=display}] 2019-12-03 14:03:48.309 10173-15301/com.tss.testfcmraw V/FA: Connecting to remote service 2019-12-03 14:03:48.330 10173-15301/com.tss.testfcmraw D/FA: Connected to remote service 2019-12-03 14:03:48.333 10173-15301/com.tss.testfcmraw V/FA: Processing queued up service tasks: 1 2019-12-03 14:03:48.367 4931-15302/? V/FA-SVC: Logging event: origin=fcm,name=notification_receive(_nr),params=Bundle[{ga_event_origin(_o)=fcm, message_type(_nmc)=display}] 2019-12-03 14:03:48.395 4931-15302/? V/FA-SVC: Saving event, name, data size: notification_receive(_nr), 35 2019-12-03 14:03:48.396 4931-15302/? V/FA-SVC: Event recorded: Event{appId='com.tss.testfcmraw', name='notification_receive(_nr)', params=Bundle[{ga_event_origin(_o)=fcm, message_type(_nmc)=display}]} 2019-12-03 14:03:48.398 4931-15302/? V/FA-SVC: Upload scheduled in approximately ms: 3047320 2019-12-03 14:03:48.399 4931-15302/? V/FA-SVC: Cancelling job. JobID: 812057698 2019-12-03 14:03:48.402 4931-15302/? V/FA-SVC: Scheduling upload with GcmTaskService 2019-12-03 14:03:48.402 4931-15302/? V/FA-SVC: Scheduling task with Gcm. time: 3047320 2019-12-03 14:03:48.407 4931-15302/? V/FA-SVC: Background event processing time, ms: 41 2019-12-03 14:03:53.373 10173-15301/com.tss.testfcmraw V/FA: Inactivity, disconnecting from the service

Expected Results:

When turn on internet i want to get 10 notification.

Relevant Code:

// TODO(you): code here to reproduce the problem

Xing1P avatar Dec 02 '19 07:12 Xing1P

@pahnpiseth this isn't enough information to tell what's going on here. Can you show more about how you're sending these messages? Is the behavior thee same if the device stays online the whole time?

samtstern avatar Dec 02 '19 18:12 samtstern

i'm edited hope it enough info...please help.

Xing1P avatar Dec 03 '19 03:12 Xing1P

@pahnpiseth you mention

send with notification payload for background notification. but if send without "notification" payload i receive notification is normal when send while device off internet and then device turn on internet.

Your example payload has a notification object defined. So is the problem happening with or without the notification payload?

kroikie avatar Dec 03 '19 19:12 kroikie

@pahnpiseth Note that notification-messages messages with a notification payload object are collapsed on the server by default if no collapse_key is defined. You can manually define a collapse_key to keep these messages from collapsing on each other. However you are limited on the number of concurrent collapse keys that the FCM backend will maintain.

Does this resolve your issue?

kroikie avatar Dec 03 '19 20:12 kroikie

okay,brother mean when send message fcm with "notification" payload cannot use with non-collapse key?

Xing1P avatar Dec 04 '19 11:12 Xing1P

okay,brother mean when send message fcm with "notification" payload cannot use with non-collapse key?

FCM document not mention this.

Xing1P avatar Dec 06 '19 02:12 Xing1P

I have checked with and without collapse key but only last message come when turn on internet. Please tell me how to fix this issue or give some suggestion to fix it.

macroday avatar Mar 09 '20 13:03 macroday

send with notification payload for background notification. but if send without "notification" payload i receive notification is normal when send while device off internet and then device turn on internet. https://fcm.googleapis.com/fcm/send

{
	"to":"....",
	"data":{
		"destination":"1",
		"source":"2",
		"badge":"1"},
	"notification":{
			"title":"Hello7","body":"Hello Test"
		},
	"priority":"high"
}

Step 1: Describe your environment

  • Android device: test on Pixel 2xl,Oneplus6,Oppo F7
  • Android OS version: Android 10,9,8
  • Google Play Services version: Last
  • Firebase/Play Services SDK version: Last

Step 2: Describe the problem:

Steps to reproduce:

  1. Turn off internet
  2. send fcm message 10
  3. Turn on internet
  4. Receive only last one message and 9 message not receive Note**: but when send notification while device online notification receive normal

Observed Results:

2019-12-03 14:03:47.765 4931-4931/? V/FA-SVC: NetworkBroadcastReceiver received action: android.net.conn.CONNECTIVITY_CHANGE 2019-12-03 14:03:47.801 4931-15302/? V/FA-SVC: Unregistering connectivity change receiver 2019-12-03 14:03:47.802 4931-15302/? V/FA-SVC: Upload scheduled in approximately ms: 3047916 2019-12-03 14:03:47.802 4931-15302/? V/FA-SVC: Cancelling job. JobID: 812057698 2019-12-03 14:03:47.811 4931-15302/? V/FA-SVC: Scheduling upload with GcmTaskService 2019-12-03 14:03:47.811 4931-15302/? V/FA-SVC: Scheduling task with Gcm. time: 3047916 2019-12-03 14:03:48.216 10173-15301/com.tss.testfcmraw D/FA: Logging event (FE): notification_receive(_nr), Bundle[{ga_event_origin(_o)=fcm, message_type(_nmc)=display}] 2019-12-03 14:03:48.309 10173-15301/com.tss.testfcmraw V/FA: Connecting to remote service 2019-12-03 14:03:48.330 10173-15301/com.tss.testfcmraw D/FA: Connected to remote service 2019-12-03 14:03:48.333 10173-15301/com.tss.testfcmraw V/FA: Processing queued up service tasks: 1 2019-12-03 14:03:48.367 4931-15302/? V/FA-SVC: Logging event: origin=fcm,name=notification_receive(_nr),params=Bundle[{ga_event_origin(_o)=fcm, message_type(_nmc)=display}] 2019-12-03 14:03:48.395 4931-15302/? V/FA-SVC: Saving event, name, data size: notification_receive(_nr), 35 2019-12-03 14:03:48.396 4931-15302/? V/FA-SVC: Event recorded: Event{appId='com.tss.testfcmraw', name='notification_receive(_nr)', params=Bundle[{ga_event_origin(_o)=fcm, message_type(_nmc)=display}]} 2019-12-03 14:03:48.398 4931-15302/? V/FA-SVC: Upload scheduled in approximately ms: 3047320 2019-12-03 14:03:48.399 4931-15302/? V/FA-SVC: Cancelling job. JobID: 812057698 2019-12-03 14:03:48.402 4931-15302/? V/FA-SVC: Scheduling upload with GcmTaskService 2019-12-03 14:03:48.402 4931-15302/? V/FA-SVC: Scheduling task with Gcm. time: 3047320 2019-12-03 14:03:48.407 4931-15302/? V/FA-SVC: Background event processing time, ms: 41 2019-12-03 14:03:53.373 10173-15301/com.tss.testfcmraw V/FA: Inactivity, disconnecting from the service

Expected Results:

When turn on internet i want to get 10 notification.

Relevant Code:

// TODO(you): code here to reproduce the problem

Sammy826 avatar Mar 11 '21 09:03 Sammy826

@pahnpiseth this isn't enough information to tell what's going on here. Can you show more about how you're sending these messages? Is the behavior thee same if the device stays online the whole time?

Sammy826 avatar Mar 13 '21 08:03 Sammy826

Hello,

is there any solution to this issue?

I have also been trying to this

i tested this with the tool from the FCM https://console.firebase.google.com/project/__/notification/compose

while it is successfully receives all notification when it is online, once the device turns offline. Sending multiple FCM notifications and once the network have return. Only the last FCM notification will be receive.

hoping to get some solutions

ArthurKun21 avatar Nov 25 '21 13:11 ArthurKun21

😭😭😭😭m

nnnn

danielaxo avatar Jun 23 '22 10:06 danielaxo

Has anyone solved this issue yet?

Msalati avatar Jul 06 '23 06:07 Msalati

Same problem

untrueme avatar Jul 06 '23 10:07 untrueme

i'm having the same issue

zell180 avatar Jul 17 '23 16:07 zell180

The issue is still present unfortunately and I've had tested it in all possible scenarios.

I've read the Firebase documentation carefully to attempt and figure out a solution. nothing seems to fix this yet.

I've been using the Firebase legacy API and I've upgraded to Firebase Cloud Messaging API (V1) to verify whether or not the issue was caused by the legacy API, I can confirm it happens on both.

Steps to produce if anyone is still uncertain about how it happens: 1- Have a device FCM registered and has opened the app at least once. (tested on a physical android phone) 2- Turn off the internet on that device. 3- Attempt sending various messages to that device e.g. 5 Messages. 4- Turn on the internet

You will notice that only the last message out of the five messages will be delivered.

I've played around with the priorities just in case but no luck it keeps on happening.

Msalati avatar Jul 23 '23 21:07 Msalati

Hello everyone, I'm trying to clarify this problem which in reality is not a problem but depends on how Android and Firebase decide to manage notifications.

There are two types of notifications:

  1. those that contain the key of the json notification and data
  2. those that instead contain only the given key data without the notification key

As per Google documentation, notifications that have the notification key are considered "always collapsible" https://firebase.google.com/docs/cloud-messaging/concept-options

This means that when the notifications are sent, a collapse_key with this value com.organization.myapp is automatically added in the json of the notification

Even if you try to change this value by changing the "collapse_key" key to a random value that always change, the Firebase SDK will overwrite that value again with "com.organization.myapp" on sending the notification.

In this way, exactly the behavior we complain about is manifested: if we put the smartphone in airplane mode and send 5 notifications, we will only receive the last one. This is because the collapse_key is always the same and therefore FCM will overwrite the notifications with the same key keeping only the last one and delivering only that one to the user.

If, on the other hand, we send a notification without the notification key and only with the data key, this will have no "collapse_key" and in this way all notifications will be delivered without any problems.

Obviously notifications without the notification key are not delivered to the user like those that do contain it and therefore a personal way must be created to make the notification pop-up appear on the user's smartphone

zell180 avatar Jul 24 '23 08:07 zell180

i've tried to implement data notifications only, the results are the same

untrueme avatar Jul 24 '23 08:07 untrueme

i've tried to implement data notifications only, the results are the same

impossible, i was stuck on that problem and i've solved it. you specifiy "collapse_key" in your json? can you post your notification json or configuration?

zell180 avatar Jul 24 '23 08:07 zell180

await messaging.send({
        token: 'token',
        data: {
            'messageId': messageId.toString(),
        },
        android: {
            priority: "high",
            notification: {
                sound: "default",
                default_vibrate_timings: false,
                vibrate_timings: ['0.1s', '0.5s', '0.1s', '0.5s'],
            },
            "ttl": 240000
        }

untrueme avatar Jul 24 '23 15:07 untrueme

await messaging.send({
        token: 'token',
        data: {
            'messageId': messageId.toString(),
        },
        android: {
            priority: "high",
            notification: {
                sound: "default",
                default_vibrate_timings: false,
                vibrate_timings: ['0.1s', '0.5s', '0.1s', '0.5s'],
            },
            "ttl": 240000
        }

You are using "notification" key inside "android" key. is the same of use "notification" in root of message configuration. "android" key is specific for Android but in this way you're sending a notification+data noitification

zell180 avatar Jul 24 '23 15:07 zell180

without notification key notifications doesn't appear

untrueme avatar Jul 24 '23 15:07 untrueme

without notification key notifications doesn't appear

And this is what i've write. if you want non collapsible notification you need to use external library to show notification pop-up, for example notifee, or write you're own way to show notification pop-up when you receive notification. This is the only way. Sounds crazy but on android notifications works in this way

zell180 avatar Jul 24 '23 15:07 zell180

Data messages works good. Thanks!

untrueme avatar Jul 25 '23 11:07 untrueme

Please do leave code guys, If anyone solved the problem...I'm stuck

atultiwaree avatar Aug 04 '23 08:08 atultiwaree

await messaging.send({
                                    token: token,
                                    data: {
                                        'title': title,
                                        'body': body
                                    },
                                    android: {
                                        priority: "high",
                                        ttl: ttl
                                    }
                                });

hope it will help

untrueme avatar Aug 04 '23 08:08 untrueme

await messaging.send({
                                    token: token,
                                    data: {
                                        'title': title,
                                        'body': body
                                    },
                                    android: {
                                        priority: "high",
                                        ttl: ttl
                                    }
                                });

hope it will help

Thanks @untrueme I'll use notifee to handle the notification

atultiwaree avatar Aug 04 '23 08:08 atultiwaree

Hello everyone, I'm trying to clarify this problem which in reality is not a problem but depends on how Android and Firebase decide to manage notifications.

There are two types of notifications:

  1. those that contain the key of the json notification and data
  2. those that instead contain only the given key data without the notification key

As per Google documentation, notifications that have the notification key are considered "always collapsible" https://firebase.google.com/docs/cloud-messaging/concept-options

This means that when the notifications are sent, a collapse_key with this value com.organization.myapp is automatically added in the json of the notification

Even if you try to change this value by changing the "collapse_key" key to a random value that always change, the Firebase SDK will overwrite that value again with "com.organization.myapp" on sending the notification.

In this way, exactly the behavior we complain about is manifested: if we put the smartphone in airplane mode and send 5 notifications, we will only receive the last one. This is because the collapse_key is always the same and therefore FCM will overwrite the notifications with the same key keeping only the last one and delivering only that one to the user.

If, on the other hand, we send a notification without the notification key and only with the data key, this will have no "collapse_key" and in this way all notifications will be delivered without any problems.

Obviously notifications without the notification key are not delivered to the user like those that do contain it and therefore a personal way must be created to make the notification pop-up appear on the user's smartphone

this soluation is worked for me also need to handle background notification beside

magdyebrahim24 avatar Aug 15 '23 16:08 magdyebrahim24

I've tested the solution suggested by @zell180 , it only works when the app is opened (open the app, turn off wifi, send notifications, turn on wifi). But when the app is closed, no notification is received, until I open it and then I receive again one notification

Anyone has some updates on this?

MiloudiMohamed avatar Dec 13 '23 21:12 MiloudiMohamed

I've tested the solution suggested by @zell180 , it only works when the app is opened (open the app, turn off wifi, send notifications, turn on wifi). But when the app is closed, no notification is received, until I open it and then I receive again one notification

Anyone has some updates on this?

Can you paste notification that you’re try to send? Android or iOS?

zell180 avatar Dec 13 '23 21:12 zell180

I'm using and testing on Android only

await messaging.send({
  token: 'abc123',
  data: {
      title: 'the title',
      body: 'the body',
  },
  android: {
      priority: "high",
      ttl: '2419200s'
  }
})

This as I said works when the app is open, but get ignored when it's not

MiloudiMohamed avatar Dec 13 '23 21:12 MiloudiMohamed