5

Edit 24/11/2016: I've just received word from Firebase Support. They suggest this is an Asus issue. The device I'm using is an Asus ZenFone 2 Laser. Here's their response:

The issue here is that Google does not control how manufacturers customize their version of android. If Asus is following the Android guidelines, then the notification should work (like on the other devices).

One thing that we found is that some phones put the apps in force-stop state, which prevents the app from receiving the notification.

From your test result this doesn't seems to be the case. BUT there are many other ways in which Asus can stop notifications from working, and unfortunately we cannot check all of them.

It would be best for you to contact Asus support and let us know if there are any news.

As this is a low priority issue for my client, I'm not going to pursue it further at the moment. I unfortunately don't have the time to test the same issue on other devices. If this changes in the future and I'll update this issue accirdingly. Until now, I will consider this unsolved. I would be interested to hear if others are having the same issues on other brand phones.

As for Asus users, there's one thing to consider: There are power saving settings that disable notificaitons.

Edit 30/09/2016: I've contacted Firebase support about this issue. They seem to agree with what Arthur Thompson is saying:

  • Stopped apps should not receive messages.
  • Swiping an app from the recent list should not stop an app.

The interesting part is that my app doesn't seem to be stopped. When running adb shell dumpsys package | grep stopped my package returns:

User 0:  installed=true hidden=false stopped=false notLaunched=false enabled=0

This indicates it's not stopped and should still receive messages (according to the very helpful Firebase Support engineer). However the app is not receiving the messages.

Edit 27/09/2016: I've omitted the notification object in the payload and moved that information do the data object instead. This doesn't solve the issue. I think I haven't been clear enough on what the issue is. The issue is that when the app is killed (swiped out of recent) the service doesn't get called or receive notifications anymore.

Original post

There's similar posts out there, but none that address this issue or give a solution.

I'm implementing FCM to get notifications. (I'm fairly new at FCM.) The message payload is a combo of both notification and data. When the app is in the foreground the service fires the onMessageReceived(). When the app is in the background (i.e. I push the home button), onMessageReceived() doesn't fire (as expected) but simply shows a notification. I can still see the log statements on MyFirebaseMessagingService.onCreate() and onDestroy(), which is great.

Now when I close the app by pushing the 'recent apps' button, and swiping the app out of the list, I no longer receive any notifications. onCreate() and onDestroy() are no longer called. No notification appears. I would like a notification to appear in this scenario too.

Example payload:

{
    "to":"token",
    "priority":"high",
    "notification": {
        "body":"hello",
        "title":"Message from Mom",
        "click_action":"ACTIVITY_MAIN"
    },
    "data":{
        "open":"chat"
    }
}

FCM Service:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onCreate() {
        super.onCreate();
        Log.v(DmcApplication.TAG, "Service Created");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.v(DmcApplication.TAG, "Service Destroyed...");
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.v(DmcApplication.TAG, "Message received!");
        EventBus.getDefault().post(new MessageEvent(remoteMessage.getNotification().getBody()));
    }

}

Bit of the manifest (in case relevant)

<service
    android:name="com.example.package.myFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Logs:

//Log when app is in foreground and message comes in:
V/coo: Service Created
V/coo: Message received!
V/coo: Service Destroyed...

//Log when app is in background and message comes in:
V/coo: Service Created
V/coo: Service Destroyed...

//Log when app is killed:
<silence...>

Any help would be greatly appreciated as I've been stuck with this for days now.

Coo
  • 1,842
  • 3
  • 19
  • 37
  • 2
    This is expected behavior: Notification messages are handled by the system when your app is not active. If you always want your app to handle the message, send a data message without a notification object. See [this section in the Firebase documentation](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages) and [this answer I just wrote](http://stackoverflow.com/questions/39695743/unable-to-insert-record-into-sqlite-database-from-firebase-message-service-when/39704853#39704853). – Frank van Puffelen Sep 26 '16 at 14:24
  • @FrankvanPuffelen I've changed it to omit the notification object, but the same issue remains. when the app is inactive, things work fine. When it's closed, notifications get ignored, and the service never gets started. – Coo Sep 27 '16 at 02:27
  • 1
    Been seeing a lot of this type of inquiry and it's all pretty much the same. See these answers: http://stackoverflow.com/a/37429495/4625829, http://stackoverflow.com/a/39505298/4625829. There are some details in the second answer specifically in the comments section from different users that might also give you ideas. – AL. Sep 27 '16 at 06:41
  • 2
    When an app is killed it should only be woken up by user action, that is, 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 recents list, this is incorrect behaviour, what device are you seeing this with? – Arthur Thompson Sep 27 '16 at 20:50
  • I'm using an Asus Zenfone 2 laser. Android Marshmellow. – Coo Sep 30 '16 at 02:52
  • @AL. That links to an incredibly interesting post on SE! Thank you! (For those interested http://android.stackexchange.com/questions/19987/what-actually-happens-when-you-swipe-an-app-out-of-the-recent-apps-list/20663#20663) – Coo Sep 30 '16 at 03:21
  • 1
    @Coo Thought of the same thing. Feel free to upvote the posts and answers that you think were helpful. Cheers! – AL. Sep 30 '16 at 03:22
  • Same issue, any solution ? – Fayçal Nov 15 '16 at 15:00
  • 2
    @BackPacker Nope, not yet. I got an email from Firebase a week or so back saying "Sorry for the late reply, we're still looking into it". So I have some hope it'll happen. When it does I'll be sure to update. – Coo Nov 16 '16 at 01:53
  • @BackPacker The issue has been updated, check OP. – Coo Nov 24 '16 at 03:47

1 Answers1

2

I ran into the same issue, looking at your "priority:high" string it looks like you are sending to Android and iOS. I ended up getting rid of the notification portion of the message and just putting the information that I needed into the data message. The data payload part triggers your service even when it is backgrounded or removed from recent apps.

On my server I check to see if the user registered their token from an iOS device or an Android device and send out the payload accordingly with the notification payload for iOS devices and the data payload for Android devices.

Jeremiah
  • 41
  • 3
  • I just changed my code to omit the notification object and put everything in data. This changes when `onMessageReceived()` is called, but that was never the issue. The issue (which remains after this change) is that when the app is 'killed' nothing happens. The service isn't started at all. The notification disappears into oblivion. – Coo Sep 27 '16 at 02:24
  • 2
    If the app is killed it will not receive notifications regardless of the format of the notification. – Arthur Thompson Sep 27 '16 at 20:51