Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM data message not received in Android when the application is in background

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.

like image 774
fralbo Avatar asked Jul 02 '16 16:07

fralbo


1 Answers

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.

like image 60
fralbo Avatar answered Sep 17 '22 21:09

fralbo