已删除(已折叠)邮件的Firebase通知值已返回

时间:2016-11-08 01:11:29

标签: android firebase firebase-cloud-messaging

我正在将GCM项目迁移到Firebase,现在我在onMessageReceived工作时已经知道了,我正在尝试根据Firebase文档弄清楚如何处理这种情况;

  

可以存储100条消息,但不会折叠。如果达到限制,则丢弃所有存储的消息。当设备重新联机时,它会收到一条特殊消息,指示已达到限制。然后,应用可以正常处理这种情况,通常是从应用服务器请求完全同步。

我现有的GCM代码可以正常工作,然后选择这样的特殊信息;

public void onReceive(Context context, Bundle bundle) {

    // Pick up various parameters here
    String nhMSG0124 = bundle.getString("information");
    ...

   // Check for special message when limit of 100 messages         
   // that can be stored without collapsing is exceeded
   // message_type value is always the string "deleted_messages"
   // total_deleted value is a string with the number of deleted messages

    String gcm_message_type = bundle.getString("message_type");
    String gcm_total_deleted = bundle.getString("total_deleted");
    if (gcm_message_type... 
                            do something else here

到目前为止,我在FCM文档中找不到任何成功,但是我想代码看起来像这样,只是不确定已删除的消息的功能是什么,或者标志是在通知本身还是在数据中;

public void onMessageReceived(RemoteMessage remoteMessage) {
    String nhMSG0124 = remoteMessage.getData().get("information");
    ...
    String gcm_message_type = remoteMessage.get...  what.?    ("message_type");
    String gcm_total_deleted = remoteMessage.get... what.?     ("total_deleted");
    if (gcm_message_type ...etc...

还有其他人想过这个吗??

欢迎任何帮助,欢呼!

1 个答案:

答案 0 :(得分:0)

我想我有这个排序。重新阅读Firebase文档,看起来消息删除会导致MESSAGING_EVENT如下所示,而GCM在通知包中使用了特殊参数。

public void onDeletedMessages ()
    then do process...

    Called when GCM server deletes pending messages due to exceeded storage limits, 
    for example, when the device cannot be reached for an extended period of time.

https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService

经过测试的应用并验证已解决..!