有没有办法在通知内容显示在设备上之前对其进行更改?例如:我有一个名为John的用户,该用户订阅了一个名为food的主题,我向该主题发送了一个推送通知,标题为“Good morning username”,但设备将显示“Good morning John”。

我想知道这是否可以在android或iOS上以及如何

最佳答案

对于 Android
是的,可以通过覆盖onMessageReceivedFirebaseMessagingService

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // Check your notification is not null and subcribed to `food` topic.
    if(remoteMessage.getFrom() == "food" &&
        remoteMessage.getNotification() != null){
        String title = remoteMessage.getNotification().getTitle(); // Title from the notification. E.g `Good morning`

        // Get the `username` of the user stored in the device. Use SharedPreference.

        String message = title + " " + username; // "Good morning username"
        // Call your notification here.
    }
}

10-08 18:25