Skip to main content
Android
iOS
Web
Windows
Unity
Flutter
React Native

Parse push 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:


_29
public class FCMMSGService extends FirebaseMessagingService {
_29
@Override
_29
public void onMessageReceived(RemoteMessage remoteMessage) {
_29
super.onMessageReceived(remoteMessage);
_29
if (remoteMessage.getData().size() > 0) {
_29
String f = remoteMessage.getData().get("f");
_29
String t = remoteMessage.getData().get("t");
_29
String m = remoteMessage.getData().get("m");
_29
String g = remoteMessage.getData().get("g");
_29
Object e = remoteMessage.getData().get("e");
_29
}
_29
}
_29
_29
@Override
_29
public void handleIntent ( @NonNull Intent intent ) {
_29
super.handleIntent(intent);
_29
Bundle bundle = intent . getExtras();
_29
if (bundle != null) {
_29
Map<String, Object> map = new HashMap<>();
_29
for (String key : bundle.keySet()) {
_29
if (!TextUtils.isEmpty(key)) {
_29
Object content = bundle.get(key);
_29
map.put(key, content);
_29
}
_29
}
_29
Log.i(TAG, "handleIntent: " + map);
_29
}
_29
}
_29
}

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:


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

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


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

vundefined