Can Firebase console push notification if apps is closed? (User swipe away with the long click menu)
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.
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:
- When my app is swiped off i can only get system tray notifications, as expected.
- When i kill my application, i can't receive any notification.
- Weirdly, when i shutdown my cellphone, push as many notifications as i can, wake it up and open my app, i still receive all of the push notifications (Why not when app is killed?).
What i've tried:
- Create a START_STICKY service (extending 'Service' class) running in a different process to "wake-up" my FCM service, but that approach is not working. I do receive the FCM message intent, onStartCommand method get's triggered, but i can't start up my FirebaseMessagingService (application process is dead). The notification and all it's important data are now lost. If the app is in foreground, it works at least.
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.
- Have you remove your notification getbody method at FirebaseMessagingService?
- Did you handle the data at OnMessageReceived() method?
- Do your devices have security apps? If yes did you allow auto start for your apps? harshil007 at above mentioned that some device's security apps block the intentService( FirebaseMessagingService in this case) from starting if auto start not allowed.
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 ?