Is it possible to receive FCM push notification when app is killed?

匆匆过客 提交于 2020-05-11 03:27:52

问题


I am developing an e-mail app in which I want that the user will get push notification as soon as they receive new email. And for that purpose I am using FCM. I have just tried push notifications using fcm by following this link: https://www.youtube.com/watch?v=XijS62iP1Xo&t=6s in order to test what features fcm provides. But the problem I face is that device recieve push notification when app is either in foreground or background but it wont receive any push notifications when app is closed (Swipe or clear from the task manager). I dont know how to achieve this via fcm? I want to receive push notifications just like whatsApp and facebook.

Every kind of help is appreciated. Thanks in advance.


回答1:


There are 2 types of push notifications: Data messages and Notification messages.

If you are using the Data messages you will be in charge of handling the received message and present a notification to the user (if needed of course). But in this case you might miss notifications when your app is closed.

If you are using Notification Messages, FCM is handling the message for you and directly displays a notification if the app is in background/closed.

Please see more here.




回答2:


Yes only if you consider sending data payloads not notifications and handle it in onMessage()

get more info here

How to handle firebase notification on background as well as foreground?




回答3:


If your App is Killed or in background,check for the Payload in your Launching Screen in My case it is MainActivity so in onCreate() Check for Extras:

if (getIntent().getExtras() != null) {
    for (String key : getIntent().getExtras().keySet()) {
        Object value = getIntent().getExtras().get(key);
        Log.d("MainActivity: ", "Key: " + key + " Value: " + value);
    }
}


来源:https://stackoverflow.com/questions/47398812/is-it-possible-to-receive-fcm-push-notification-when-app-is-killed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!