Skip to content

Android FCM not waking up #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dangvohoanganhvn opened this issue Dec 10, 2019 · 9 comments
Closed

Android FCM not waking up #40

dangvohoanganhvn opened this issue Dec 10, 2019 · 9 comments
Labels
closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question

Comments

@dangvohoanganhvn
Copy link

dangvohoanganhvn commented Dec 10, 2019

Hi team,
I'm using Firebase C++ SDK quick start messaging to get familiar with Android FCM. After I set up completely, Although I can receive notifications from server, quick start messaging app did not wake up. How can I solve this problem. Thanks.

Platform: Android (built by MAC OS)
Device: Samsung J7
Firebase C++ SDK version: 6.8

@google-oss-bot
Copy link

This issue does not seem to follow the issue template. Make sure you provide all the required information.

@cynthiajoan
Copy link

cynthiajoan commented Dec 13, 2019

@dangvohoanganhvn could you please try using sample app to see if it has the same behavior?

If you are actually using the sample app, could you describe a bit more of what's the expected behavior and what you actually see happening? Thanks!

@cynthiajoan cynthiajoan added needs-info Need information for the developer type: question labels Dec 13, 2019
@cynthiajoan cynthiajoan changed the title [APP DOES NOT WAKE UP] Android FCM not waking up Dec 13, 2019
@dangvohoanganhvn
Copy link
Author

@cynthiajoan Actually, I'm using sample app. The Logs in loop "while (listener.PollMessage(&message))" just printed on Logcat when I start the app. Is there some C++ API that will be called when my device receive a notification ? I tested Java code and it worked well (see in the attached picture) , the function onMessageReceived will be called when my device receive a notification.Thanks!

image

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Dec 16, 2019
@chkuang-g
Copy link
Collaborator

chkuang-g commented Feb 6, 2020

Hi @dangvohoanganhvn

Although I can receive notifications from server, quick start messaging app did not wake up.

I believe what you meant was: when you put the app in the background, not killed the app, you can still received the push notification. However, the app did not "wake up" and the listener you added through C++ API was not triggered. Is that what you mean?

TL; DR; If so, I think it is an intended behavior.

In your scenario, you should still receive cached ::firebase::messaging::Listener::OnMessage() event from C++ SDK once you relaunch the app or put the app back to foreground, but with a catch. C++ OnMessage() will not be called if the message contains notification data, since the notification data is passed to your app, which is a Android activity, through Intent, when you click on the notification in Android system tray. A bit more information from here about how messages are handled in different cases.
However, you can override Android Activity to forward the message from the Intent to our customized ListenerService in order to trigger OnMessage() function.

If you need to process the message immediately when the device receive a message, the only way is thru what you are doing right now, override a ListenerService in Java. Here is more detail about it. And again, ListenerService will not receive messages with notification data, as described above. Also, ListenerService is an Android service, which is different from your app, which is an Android activity. You cannot wake your app from a service, AFAIK. And the default behavior of this ListenerService would actually cache received message and makes them available when your app is back to foreground again.

This is just a result of the design of Android SDK, which make the event only available in a service, and the design of C++ SDK, where we want the event to be available in an app, e.g. an Android Activity.

In conclusion, if you don't need to process the message immediately, but still want to trigger the C++ event when the user clicks on the notification from the system tray, the most general solution is by, again, modifying Activity.

Hope this helps!

Shawn

@chkuang-g chkuang-g added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Feb 6, 2020
@dangvohoanganhvn
Copy link
Author

dangvohoanganhvn commented Feb 6, 2020

Hi @dangvohoanganhvn

Although I can receive notifications from server, quick start messaging app did not wake up.

I believe what you means is: when you put the app in the background, not killed the app, you can still received the push notification. However, the app did not "wake up" and the listener you added through C++ API was not triggered. Is that what you mean?

TL; DR; If so, I think it is an intended behavior.

In your scenario, you should still receive cached ::firebase::messaging::Listener::OnMessage() event from C++ SDK once you relaunch the app or put the app back to foreground, but with a catch. C++ OnMessage() will not be called if the message contains notification data, since the notification data is passed to your app, which is a Android activity, through Intent, when you click on the notification in Android system tray. A bit more information from here about how messages are handled in different cases.
However, you can override Android Activity to forward the message from the Intent to our customized ListenerService in order to trigger OnMessage() function.

If you need to process the message immediately when the device receive a message, the only way is thru what you are doing right now, override a ListenerService in Java. Here is more detail about it. And again, ListenerService will not receive messages with notification data, as described above. Also, ListenerService is an Android service, which is different from your app, which is an Android activity. You cannot wake your app from a service, AFAIK. And the default behavior of this ListenerService would actually cache received message and makes them available when your app is back to foreground again.

This is just a result of the design of Android SDK, which make the event only available a service, and the design of C++ SDK, where we want the event to be available in an app, e.g. an Android Activity.

In conclusion, if you don't need to process the message immediately, but still want to trigger the C++ event when the user clicks on the notification from the system tray, the most general solution is by, again, modifying Activity.

Hope this helps!

Shawn

Hi Shawn, Thanks for your help!

However, my expectation is that, when my application was killed ,it can receive the notification and call onMessage() C++ function without opening my application and user actions. What should I do? Please give me some helps.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Feb 6, 2020
@chkuang-g
Copy link
Collaborator

chkuang-g commented Feb 6, 2020

It is basically impossible by design.

When your app is killed or stay in the background for way too long, the only way to wake your app is through Intent. Take a look of this doc. That means you would need to implement your own FirebaseMessageService and start the activity with the Intent. From your app side, you would need to specify which Intent your app is listening to in AndroidManifest.xml. And you will need to process the Intent from your app when it is awake.

All these work still won't trigger OnMessage() function in C++.

We don't do this in C++ SDK because we do not want to launch the app everytime when the device receives a cloud message. Think about the chaos. 😂

May I learn why you need to process the message immediately even when the app is killed?

@chkuang-g chkuang-g added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Feb 6, 2020
@chkuang-g
Copy link
Collaborator

correction

I think Android stop allowing you to start an activity from a service. That is in general a very bad idea to do so.

If you really need to do something about the message immediately, you can extend ListenerService or FirebaseMessageService directly, like what you did here. But you also run into the limited about different types of message..

@google-oss-bot google-oss-bot added the stale Don't have recent activity label Feb 14, 2020
@google-oss-bot
Copy link

Hey @dangvohoanganhvn. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link

Since there haven't been any recent updates here, I am going to close this issue.

@dangvohoanganhvn if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question
Projects
None yet
Development

No branches or pull requests

4 participants