4

I'm switching from GCM to FCM. I only use it to send messages to my server trough FCM. I extended FirebaseMessagingService to implement the callbacks. For example, onSendError() works just fine, but onMessageSent() is never executed... I don't know if it is relevant, but I send the 'ack' stanza from my server when the message is received.

My FirebaseMessegingService class:

public class FCMListenerService extends FirebaseMessagingService {

    public FCMListenerService() {
        super();
    }

    @Override
    public void onDeletedMessages() {
        Log.d("wouter", "onDeletedMessages: ");
        super.onDeletedMessages();
    }

    @Override
    public void onMessageSent(String msgID) {
        Log.e("wouter", "##########onMessageSent: " + msgID );
        super.onMessageSent(msgID);
        Database database = new Database(this);
        database.confirmFCMMessageSend(msgID);
        database.closeDatabase();
    }

    @Override
    public void onSendError(String msgID, Exception exception) {
        Log.e("wouter", "onSendError ", exception );
        super.onSendError(msgID, exception);
        Database database = new Database(this);
        database.eraseFCMMsgIDFromFGMMessageLog(msgID);
        database.closeDatabase();
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    }
}

And the relevant part of my Manifest:

<service android:name=".FCM.FCMListenerService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
Aleksandar G
  • 1,163
  • 2
  • 20
  • 25
  • How many messages did you try to send? The acks to onMessageSent are batched so when you send a message successfully you may not receive a callback for some time. This is to help with battery life. Try sending 10 or more upstream messages, you should receive an onMessageSent callback after about 10 messages. – Arthur Thompson Jun 07 '16 at 19:55
  • I tested a lot and did send a bunch of messages, so that's not it... – Wouter Van der Schraelen Jun 09 '16 at 08:43

1 Answers1

6

Had the same problem and the second part of this answer fixed it for me. Basically, you have to set the TTL at the message you send. Something like:

RemoteMessage myMessage = new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com").setMessageId(id).setData(data).setTtl(86400).build();
Community
  • 1
  • 1
Moritz
  • 1,186
  • 1
  • 8
  • 7
  • 1
    I reported this issue to the Firebase support. They acknowledged it as a bug, but couldn't provide a timeline for a fix. So maybe at some point in the future, this will be fixed. Checking out the release notes of new versions once in a while wouldn't hurt, I guess. – Moritz Nov 14 '16 at 10:08
  • This issue is still there in Firebase api. – Tasneem Mar 15 '17 at 08:58