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);
}
}
}| Parameter | Description |
|---|---|
f | The user ID of the push notification sender. |
t | The user ID of the push notification recipient. |
m | The message ID: A unique identifier of the message. |
g | The group ID: This field exists only for group messages. |
e | The 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":{}
}