2

I am trying to send upstream message using FCM as shown in code-1 below. When I send a message from FCM to the App, it arrives to the App accompanied by and delayed upstream message, what I mean be delayed upstream message is, when the App already sends an Upstream message but the App user never get notified about its status e.g onMessageSent"

what I am trying to achieve is, to get notified immediately via "FirebaseMessagingService" when I send an upstream message. to solve this issue, I used setTtl with small values and with large values between 1 to 100000 but nothing changes, I still get notified about the upstream messages only when there is a downstream message from FCM to the App

please let me know why the callbacks in "FirebaseMessagingService" do not report the status of the sent messages from the App to the server immediately

code-1:send Upstream message:

mBtnSendUpstreamMsg = (Button) findViewById(R.id.btn_send_upstream_message);
    mBtnSendUpstreamMsg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            FirebaseMessaging fm = FirebaseMessaging.getInstance();
            fm.send(new RemoteMessage.Builder("13xxxxx" + "@gcm.googleapis.com")
                    .setMessageId("2")
                    .addData("my_message", "Hello World")
                    .addData("my_action","SAY_HELLO").setTtl(1000000)
                    .build());
        }
    });

MyAndroidFirebaseMsgService.java

public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {
private final static String TAG = MyAndroidFirebaseMsgService.class.getSimpleName();

@Override
public void onMessageSent(String s) {
    super.onMessageSent(s);
    Log.d(TAG, "onMessageSent: upstream message");
}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.d(TAG, "onMessageReceived: downstream message");
    //Log data to Log Cat
    Log.d(TAG, "onMessageReceived->From: " + remoteMessage.getFrom() +" | "+ remoteMessage.getTo());
    Log.d(TAG, "onMessageReceived->Notification Message Body: " + remoteMessage.getNotification().getBody());
    //create notification
    createNotification(remoteMessage.getNotification().getBody());

    /*
    FirebaseMessaging fm = FirebaseMessaging.getInstance();
    fm.send(new RemoteMessage.Builder("135855xx" + "@gcm.googleapis.com")
            .setMessageId("2")
            .addData("my_message", "Hello World")
            .addData("my_action","SAY_HELLO").setTtl(1000000)
            .build());
            */
}
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • check FCM Token generated or not? @user2121 – Chirag Talsaniya Jul 21 '17 at 12:17
  • @ChiragTalsaniya would you please tell me what is the relation between the generated FCM Token and the delayed upstream message?anyway, the FCM Token was generated and as explained in the question, i receive the downstream messages as as they are sent but there is always a delay in the upstream messaging – Amrmsmb Jul 21 '17 at 12:19
  • Oops..misunderstood. let check for same @user2121 – Chirag Talsaniya Jul 21 '17 at 12:23
  • I have observed the same, even with a ttl of 0 – Marc Oct 09 '17 at 23:10

1 Answers1

1

You ask: ...why the callbacks in "FirebaseMessagingService" do not report the status of the sent messages from the App to the server immediately

The documentation explains:

To optimize network usage, FCM batches responses to onMessageSent and onSendError, so the acknowledgement may not be immediate for each message

As I noted in my comments to the previous version of this question, I have observed a delay of about 20 minutes for onMessageSent() to be called.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158