Closed jamesytl closed 8 years ago
Same problem here. I created simple app using the exampe app from github. When the app is foreground or background everything works as expected and described in the docs. But, when I killed the app, I can't received the push notifications ;<
@jamesytl and @fockeRR are you seeing logs in the onMessageReceived
?
@yishai-glide No, it looks like the onMessageReceived is not called. If the app is in background or foreground I see the logcat output from onMessageReceived
@fockeRR @yishai-glide It seems like it depends on device being tested. When I use Oppo phone the apps will no longer receive notification when the app is "swiped off". However, RedMi Note 3 will still receive notification if I perform the same action. So probably could say that its android phones with different OS messing with us and causing headaches
@jamesytl I am using RedMi Note 3 and facing the same problem. The app can receive notifications while running in foreground or background, but won't receive notifications when the app is killed. The same application is working fine on Nexus 5. Also I have another application which uses GCM implementation to receive notifications and it works fine on both devices even when the application is killed.
@harshil007 With your working GCM implementation are you also sending messages from the Firebase console (notification messages) or are you using data only messages?
Update : Tested using 2 RedMi Note 3 with different ROM.
One worked perfectly as how I wanted( Able to receive notification even if swiped off, immediately receive notification after boot with broadcastreceiver)
while another phone failed miserably ( No longer receive any notification after swipe off, will never receive any notifications after reboot even if I manually start the program after boot. Re-installation of the app will instantly receive previous notifications but this situation is totally wrong because new installation should generate new registration token. Its like the notification has reached the phone but never triggered the FirebaseMessagingService to display the notification).
@kroikie Data messages only as it is a google project which I have not yet imported into the firebase console.
UPDATE : App working perfectly now in RedMi Note 3. It turns out you have to give auto start permission to the application in order to be started up after being killed.
I have a similar issue. My problem is basically that i need to receive every notification in my implementation of FirebaseMessagingService (onMessageReceived), even if app is in background or closed/killed (like messaging application services, for instance). The scenario is:
What i've tried:
Any advice will be appreciated! Thanks!
@schonmann by killing apps you mean force close right? Force close will close down an app entirely including any background services even if START_STICKY is included if I'm not mistaken.
Btw, I just learnt in last few day we should not use a service with START_STICKY to start the FCM service because FCM service is an IntentService which will automatically start its own when needed and stop itself when finished.
Not sure its relevant or not but I'm now using data payload instead of notification payload and handle the data's included in notification personally. This way the notification received will always work as how we wanted it to work instead of default FCM way of handling notification which will show notification at system tray with notification payload's head and body. This may fixed the issue of your app receiving notification only when in foreground.
You may check this link for more information.
@jamesytl I think my problem is finally solved. I was sending push messages with both data payload and notification payload, so the system tray was handling it.. hahah When i get home i will try that. Thanks!
@schonmann yup that's what I did previously too. Try sending data payload only and remember to handle it in your FirebaseMessagingService's OnMessageReceived(). Good luck coding ;)
PS: My RedMi Note 3 still have some issues like not receiving any notification until it is manually disconnect and reconnect to a Wi-Fi connection. Not sure how it works but I guess its still device dependent as the two same devices will yield different result.
@jamesytl , I can get notifications when App is Foreground/Background , But when I swiped from recent tray then Firebase Notification not coming . Any possible way to handle this ? I check same scenario in whatsup , After swiped from recent tray Whatsup Notification still coming ,even I force stop whatsup from settings but still i can get whatsup Notification.
I must want to handle notification when app is closed (wiped from recent tray) . Any possible ways please advise.
I tried , Samsung,huawei,Mi devices.
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'to' => 'fVRFdJKlgX4:APA91bG7AzLsrux5RQCeRo1ykddr_Ygl4_FAQpKYPUleVkC7NgZMJy-Wjn0smMP8H6bimfuakFGN3ZMP2UYej8tP40zOJ-RIGZhYpk1DYySifDQ0BrZUmBkKEy1dNWLgj2H84sdssTTIhNf',
'data' => array('title' => 'Working Good', 'body' => 'That is all we want','message' => 'message'),
);
Thanks in advance.
@chandrahasan Sorry for late reply and also sorry that I can't really help you because I'm not sure why yours isn't working. Just some common question when it comes to FCM notification.
By the way, can't really compare normal apps with whatsapp because it seems like it binds itself with our phone's Contact which is never closed?(at least that's what I found from little information gathered through google regarding how whatsapp's notification works)
@jamesytl same problem with @chandrahasan. But for me if app dead because killed automatically by ActivityManager. Notifications not received. I'm using Asus Zenfone with 5.0 Lolipop.
@chandrahasan and @jamesytl The Android framework advises that apps that have been stopped (not in background) should not be started without explicit user interaction. FCM follows this recommendation and thus does not deliver messages to stopped apps. What I believe is happening on the devices in question is that apps that are swiped from the recents list are being stopped and thus not receiving messages from FCM.
Note that some images may whitelist applications originally included with the image. So I'm assuming that in the case of WhatsApp it may have been whitelisted by the system and thus is not seen to be stopped at message delivery time. Swiping from the recents list should not result in applications being stopped, it should only stop the Activity.
I will take a closer look at these devices and report back here when I have more.
I send User segment notification but All user don't get push notification Why all did not get? From console.firebase.google.com I found monthly active user 4100 but when i send notification It shows 2100 send. That mean 50% user found. then what would be be others.
@tariqul000 you should create a new issue as this seems irrelevant with this issue
Is there any solution come on that issue or not ? cause i also have same issue, I receive Notification when my Mobile Screen is ON whatever the app is open or not, i got instant notification, but if i lock my Mobile more than 1 min i didn't able to receive any notification. Any Progress in that in FCM ?
I am also facing same issue with my Lenovo k5 plus.....
I Just go to settings/apps/
both option are by default selected...I unselect the second option and now my application is receiving notification all the time.
Is anyone know how to do it with programming
Can anyone tell me the final conclusion of what happens if application is killed? I'm not asking if app is in background
@all this issues are restricted by Android Devices. Several device has restrictions like Azus Zenphone. Installed new app will have recommendation to allow or disallow power management. But, app like wa, line, bbm they can force allow auto manager. Anyone can solve this issue?
Hi I have downloaded and installed quickstart messaging project.I am getting Notification message first time(when I am running application) from Firebase cosole without calling sendNotification() method which I have created in MyFirebaseMessagingService.Can anyone Please why this is sending Notification message to my mobile for the first time without calling sendNotification() method.
@kroikie that's true, I have a huawei phone (with EMUI) and I had to open the apps settings, then select my app, then battery and then play with battery tweaks, so, the operating system don't kill my app when I turned off the screen or when my app was idle by a long time. Thanks man
Is there any work around for this? I see inshorts, Times now and TOI sending notifications when the app is killed
I have the same issue on Lenovo A6020a41 even if I removed the restrict to launch
option, I still can't get the notification when the app is killed from the recent apps list.
Hi @tinyCoder32 could you check the logcat and see if your app is being stopped when it is removed from the recent apps list. We have seen some devices do this and once an app is stopped FCM will not wake it to send it a message till the user reopens the app.
Hi @kroikie I just did that, the app got killed and the logcat doesn't receive anything after that, before with GCM i used to add something like a service to the Manifest file and it was getting the notification even if the app is closed, isn't there anything similar with Firebase?
note:
if a notification arrived to the phone while the app is closed, after reopening it the next time I got all the notification data empty, nulled
. so I can't use them, they get lost if the app was closed.
I appreciate explaining if there is a solution, I found this issue asked more that 20 times on the web.
Sorry to comment on this closed incident but I think there should be a possibility to handle notifications even if the app is closed. Every messaging app is capable of doing this and many users close all their apps at once in said "long click menu". Is there a work-around or has nobody figured out how to receive notifications even if the app is closed/killed?
Hi @kroikie does the "once an app is stopped, FCM will not wake it" behaviour apply to 'notification' type messages (e.g. from FCM console) as well? Or will Android display the notification in the task bar, and tapping the notification interpreted as user interaction to start the app?
Edit: To answer my own question, the same behaviour does apply to 'notification' type messages. If you've force stopped the app then notifications are not displayed either.
Hi,Anyone found answer to the above problem? I am facing similar issue..Cant receive messages i some devices when the app is killed.
I am using Lenovo A7000 mobile for testing , i could able to receive notification when the app in Foreground or in background state but not when i closed the app from background.Is there any workaround or code snippet available from your side to overcome this issue?
@harshil007's solution worked for me. Just give the app the autostart permission. I'm sending data and notification parts at the same time and I get notifications when the app is killed.
I gave the application this permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Now it is receiving data messages even if it was killed. I wonder how this affects battery life.
is it device specific issue? if I swipe away the app from recent app, for some of devices i.e. Nexus 6P, HTC Desire, notification is received properly. But for some of devices i.e. Huawei notification can't receive.
Yes, I'm receiving "data message" only.
@alexschoeberl : any code snippet to help me as You have successfully receive notification even if app is closed.
Is the priority is set to high refer below https://firebase.google.com/docs/cloud-messaging/concept-options { "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "priority" : "high", "notification" : { "body" : "This week's edition is now available.", "title" : "NewsMagazine.com", "icon" : "new" }, "data" : { "volume" : "3.21.15", "contents" : "http://www.news-magazine.com/world-week/21659772" } }
@alexschoeberl would you mind to share your setup please? I am really blocked at this, thanks
I only target Android 6+. I use "com.google.firebase:firebase-messaging:10.0.1". I added these permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
I extended FirebaseMessagingService which includes:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
remoteMessage.getData()
}
This gets called even when the app is closed. But only in the background, without an UI. However, I only tested it on 2 Samsung devices. The most important thing is to only send data messages, without a body.
from pyfcm import FCMNotification
push_service = FCMNotification(api_key="")
r = push_service.notify_single_device(registration_id=registration_id, data_message=data)
like all above i am facing the same issue i have ASUS zenfone-5 kitkat and device is not receiving data payload messages when app is closed or swipe off from recent app's list. I have tried all possible solutions given by @harshil007 and others but still same issue is arriving. I have given both autostart & RECEIVE_BOOT_COMPLETED permissions. Now i am expecting that @kroikie in on right it's device specific because some devices creating this issue and some are not.
U r running any services?
On May 18, 2017 1:42 PM, "Bhomii" notifications@github.com wrote:
like all above i am facing the same issue i have ASUS zenfone-5 kitkat and device is not receiving data payload messages when app is closed or swipe off from recent app's list. I have tried all possible solutions given by @harshil007 https://github.com/harshil007 and others but still same issue is arriving. I have given both autostart & RECEIVE_BOOT_COMPLETED permissions. Now i am expecting that @kroikie https://github.com/kroikie in on right it's device specific because some devices creating this issue and some are not.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-android/issues/41#issuecomment-302333354, or mute the thread https://github.com/notifications/unsubscribe-auth/AKO_QbXsum84LqQ1u1nTaTxFfR4ij8suks5r6_17gaJpZM4Ivrw2 .
I've noticed that I get different behaviour depending on how the app was launched before I swiped it closed, as bizarre as that sounds.
If I launched the app with a debugger, and swipe it off, then I no longer receive FCM notifications. If I then launch the app from the launcher icon, I receive FCM notifications, and if I swipe off that 'launched from the launcher' app, I continue to receive FCM notifications. I get this behaviour on a Galaxy S4 and a Sony Xperia Z2.
Given that the easiest way for me to get the latest version of the app on the phone onto the app is to hit debug, this is something that I have to keep remembering:
When you swipe it closed, launch it from the launcher icon again, and swipe it closed again. (At least if you're testing FCM notification behaviour when the app isn't running).
@GregHNZ you are a life-saver. This was totally it (experiencing it on an LG G6 with Android 7.0).
Thanks for helping us not go insane with this. A definite Android bug!
@anki29 I am running intent service after receiving notification because i have to change some thing in database with the data i received in notification according to the notification clicked by the user. I do have multiple login in my application so i need to switch user menu before user opens the application. Is there any issue with the service? i have opened service from pending intent and after service alter the database then service itself opens the application.
@GregHNZ , unfortunately, your solution didn't worked for my Mi5. The app is force-stopped after swipe, and can't receive new notifications. Tried everything.
As I see, it's a totally device- and OS-related issue. But Watsapp and other messengers work fine with similar scenario. Their developers know something that we don't, or their apps are just so popular that vendors included them in white list? According to log, these apps are not force-stopped after swipe.
@GregHNZ you are a life-saver [2]
@GregHNZ you need to provide startup permission in MI phones so as to receive Notification. But I have seen some issue with when application in debugging mode then every time push notification is not received but in release mode by creating the apk the notification works fine. This thing is not mentioned in firebase anywhere so i am not preety sure. But in my case this was the issue
Hello People,
i'm trying to use android firebase cloud messaging for the case where the app is closed but my device never receive any push notification, is this a known issue ? is there a solution for that ?
i'm using the following format:
{
"to":"dsadsadsadsaweq341242343",
"data":{
more data in here
},
"collapseKey":"fdsfdsfdsferw32432",
"priority":"high",
"timeToLive":6960
}
btw when the app is running i'm receiving push notifications, as well as when i subscribe for topics and in that case it's working when the app runs and when it's closed. so all that is very weird.
i forgot to mention that when i use a simulator using android 7.1.1 actually the push notification is working when the app is closed on the condition i manually run the app myself.
but on my device which has lower version of android than this simulator, the push notification works only when the app runs.
i really need your help here.
Thanks.
To clarify the issue, I've email Google support to provide the real answer for us who are facing this issue. This is their answer.
Hi there,
Thanks for reaching out. Kat here from Firebase Support. I'd be happy to help you with your issue.
When an app is killed, it should only be woken up by user action (i.e. if the user taps on the app icon). So if your app is not receiving FCM messages after it is killed, then that is expected. However applications should not be killed when swiped from the recent apps list-- this is incorrect behavior.
We've actually looked into this, and apparently, on some devices, apps are being prematurely killed, (e.g. when swiped away from the recents screen). The Android platform recommends that you should not run apps that have been stopped till they are explicitly started by the user. FCM follows this recommendation and thus stopped (or killed) apps don't receive notifications.
To confirm, can you try running this from the command-line for your reported devices after swiping the app away from the recents screen: adb shell dumpsys package | grep stopped
If you get the result:
• User 0: installed=true hidden=false stopped=false notLaunched=false enabled=0 - since stopped is false, your app should get the notification. • User 0: installed=true hidden=false stopped=true notLaunched=false enabled=0 - since stopped is true, your app cannot be started to handle the incoming message. This is an issue with the device manufacturer. Kindly provide the device info so we can report this.
If you see though that other apps (such as Whatsapp, Gmail) are receiving messages, those apps may have been included in the list of the manufacturer's white-listed apps that are allowed to receive notifications in the background (not prematurely stopped).
Also, kindly check if you have any battery/power management app on your phone (some examples for Samsung, Lenovo, Huawei, Xiaomi) which may be preventing notifications from being received.
Thanks a lot @syahnurizal is this behavior on firebase cloud messaging is the same using Google Cloud Messaging ? if not it worth to stick with GCM right ?
I have tried developing a firebase notification apps with this MyFirebaseMessagingService link and MyFirebaseInstanceIDService link example that will receive notification from the console. However, if I close the apps by swiping away the app from the task manager, the app will no longer be able to receive any notification.
I have tried using a service that return START_STICKY and using it to start the MyFirebaseMessagingService but still couldn't receive any notification.
Is this how the firebase push notification intended to perform or am I doing it wrongly?
Extra Info. : My apps is working if I only click back but not if I swipe it away in task manager.