quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

Can Firebase console push notification if apps is closed? (User swipe away with the long click menu)

Open jamesytl opened this issue 10 years ago • 103 comments

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.

jamesytl avatar Jun 07 '16 08:06 jamesytl

I am also facing same issue with my Lenovo k5 plus..... I Just go to settings/apps/ In this there are two check boxes ...

  1. for Show notifications.
  2. for Restrict to launch.

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 screenshot_2016-10-19-16-19-55

a100rabh avatar Oct 19 '16 10:10 a100rabh

Can anyone tell me the final conclusion of what happens if application is killed? I'm not asking if app is in background

humzakhalid94 avatar Oct 23 '16 11:10 humzakhalid94

@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?

radityagumay avatar Nov 08 '16 06:11 radityagumay

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.

RaniRashmi avatar Nov 18 '16 09:11 RaniRashmi

@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

owaremx avatar Jan 12 '17 23:01 owaremx

Is there any work around for this? I see inshorts, Times now and TOI sending notifications when the app is killed

Sahana312 avatar Jan 18 '17 05:01 Sahana312

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.

tinyCoder32 avatar Jan 28 '17 22:01 tinyCoder32

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.

kroikie avatar Jan 29 '17 04:01 kroikie

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.

tinyCoder32 avatar Jan 29 '17 09:01 tinyCoder32

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?

robachmann avatar Feb 12 '17 18:02 robachmann

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.

GregHNZ avatar Feb 16 '17 02:02 GregHNZ

Hi,Anyone found answer to the above problem? I am facing similar issue..Cant receive messages i some devices when the app is killed.

aaadarshbisht avatar Feb 17 '17 07:02 aaadarshbisht

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?

praveenkumar66 avatar Feb 17 '17 08:02 praveenkumar66

@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.

Agraphie avatar Feb 17 '17 08:02 Agraphie

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.

alexschoeberl avatar Feb 21 '17 16:02 alexschoeberl

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.

msh-nayan avatar Feb 22 '17 06:02 msh-nayan

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" } }

christianraj avatar Feb 22 '17 06:02 christianraj

@alexschoeberl would you mind to share your setup please? I am really blocked at this, thanks

jaimeagudo avatar Apr 03 '17 18:04 jaimeagudo

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)

alexschoeberl avatar Apr 03 '17 19:04 alexschoeberl

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.

Bhomii avatar May 18 '17 08:05 Bhomii