Parse push fields

Updated

Parse push notifications fields.

After receiving a push notification, you need to parse the data.

Rewrite the FirebaseMessagingService.onMessageReceived method to get the custom extension field in the RemoteMessage object. The sample code is as follows:

public class FCMMSGService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        if (remoteMessage.getData().size() > 0) {
            String f = remoteMessage.getData().get("f");
            String t = remoteMessage.getData().get("t");
            String m = remoteMessage.getData().get("m");
            String g = remoteMessage.getData().get("g");
            Object e = remoteMessage.getData().get("e");
        }
    }

    @Override
    public  void  handleIntent ( @NonNull  Intent  intent ) {
        super.handleIntent(intent);
        Bundle bundle = intent . getExtras();
        if (bundle != null) {
            Map map = new HashMap<>();
            for (String key : bundle.keySet()) {
                if (!TextUtils.isEmpty(key)) {
                Object content = bundle.get(key);
                map.put(key, content);
                }
            }
            Log.i(TAG, "handleIntent: " + map);
        }
   }
}
ParameterDescription
fThe user ID of the push notification sender.
tThe user ID of the push notification recipient.
mThe message ID: A unique identifier of the message.
gThe group ID: This field exists only for group messages.
eThe user-defined extension field.

e is a completely user-defined extension. The data source is em_push_ext.custom of the message extension. The data structure is as follows:

{
    "em_push_ext": {
        "custom": {
            "key1": "value1",
            "key2": "value2"
        }
    }
}

The data structure of the extension in the RemoteMessage object is as follows:

{
    "t":"receiver",
    "f":"fromUsername",
    "m":"msg_id",
    "g":"group_id",
    "e":{}
}