(New) GCM message received, but how to parse?

后端 未结 3 896
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-13 11:43

I am working with the \"new\" GCM, part of Google Play Services, that does not use jars for both Android and server. Android uses Google Play apk to register, receive and even s

3条回答
  •  没有蜡笔的小新
    2021-02-13 12:27

    You have to add another level to json data, apparently they do not parse json recursively. Send:

    {...., "data":{"payload":{"id":5,"a":5}}}
    

    Then in code:

    String json = intent.getExtras().getString("payload");
    // json = {"id":5,"a":5}
    

    This can be easily converted to POJO, For me this approach is better if you have classes already ( or just want to work with objects instead of get...("xyz")

提交回复
热议问题