7

I face a very strange problem; I had a previous version of my application published using GCM 8.4.0 which worked fine. I updated some code, without changing anything about GCM and I realised that the messages where not received anymore when the application was in background. This on several different devices.

As I was unable to find any explanation, I migrated to FCM. I made few unsuccessful attempts and it began to work !?! Then I was able to send several different messages successfully without changing anything! Houra!!!!

Just before generating my signed APK, I made a last test! Arrggghhhhh.... messages were not received anymore when the application was in background!!!!

I made the test with my server, with Advance REST Request, in the same conditions as I used for successful attempts and no way, it works when the application is in foreground but no more at all when the application is in background!!!

Did you exeperience such problem???

I precise that when I receive a message with the application in foreground and I generate a notification from it, There are 2 different behaviors:

  • When the application is able to receive it in background, the notification remains when I swipe the app out from the recent apps list.

  • When the application is not able to receive it in background, as in my current case, the generated notification is removed when I swipe the application out.

Does it mean something useful?

Edit
I updated to 9.2.0 but the problem remains.

fralbo
  • 2,534
  • 4
  • 41
  • 73
  • It would be helpful to see the requests that you are making to send messages as well as the code being used to receive the messages. FCM data messages should result in a callback to onMessageReceived whether the app is in the foreground or background. – Arthur Thompson Jul 03 '16 at 15:58

2 Answers2

6

So I got it working few weeks ago but rebuilding the project with several updates, studio, sdk, java, I cannot get the same project working now anymore.

I spent few hours to explore the web, notably Stackoverflow about this problem and the answer I could do is "It depends...." I personnally got it working, it doesn't work anymore, for some of you it works, for some others it doesn't...

So I started from the FireBase quickstart-android project and what I can say is:

No, data messages are not received when the application is in background. Or maybe I would say: data-messages are not received anymore when the application is in background.

So I ask the question to Firebase-support expecting a good answer. I was really disappointed, the answer is:

Hello ... team,

Thank you for reaching out to us.

Actually data payload is not supposed to be received in background. Data message intents are delivered to the application and received inside onMessageReceived() method (which does not fire in background). Only display messages/ Notifications are delivered when the app is in background.

...

Sincerely, K...

I don't know what you think about that but for me it's a real disaster!

I don't know if it's a temporary situation or not, maybe someone could have more precise information because I cannot believe that background message reception is not supported anymore. Or at least for us because according to my logs, the device receive background messages displaying the following message:

07-18 15:28:34.371 3068-3068/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.google.firebase.quickstart.fcm (has extras) }

But the onMessageReceive() callback is not invoked!

IMPORTANT EDIT
Building this kind of project, for example FireBase quickstart-android project from command line tools perfectly works but not when you build it from IDE debug button. If you want to build your project from IDE debug button, use Android Studio 1.5 strange but works perfectly).

Complete test case is available here.

fralbo
  • 2,534
  • 4
  • 41
  • 73
  • Very interesting. And how they expect a group of users to receive same message in different language? Anyone got any ideas? – Anfet Aug 25 '16 at 09:34
  • @Anfet. In my case, when a device register to my server, I record the device language. So I know which language to use for each user. – fralbo Aug 29 '16 at 16:00
  • 2
    *Data message intents are delivered to the application and received inside onMessageReceived() method (which does not fire in background). Only display messages/ Notifications are delivered when the app is in background.* neither of these statements are true – Tim Sep 12 '16 at 09:35
3

Sorry, I didn't pay attention that delay_while_idle was set to true by mistake.

Edit
The behavior is strange anyway because even with delay_while_idle= true, my previously published application using GCM 8.4.0 and built with Studio 1.5.2, receives messages while in background.
The same project rebuilt with Studio 2.1.2. (nothing changed in the project except the asked update to gradle 2.1.2) doesn't receive the messages while in background, which is the expected behavior.
But it doesn't receive it either while coming in foreground!
Updating to FCM 9.2.0 works similarly, i.e. it doesn't receive messages while in background, ok, but it doesn't receive it while coming in foreground, which seems not correct.

** EDIT 2 **

I definitively cannot get it working anymore

fralbo
  • 2,534
  • 4
  • 41
  • 73