有没有办法在通知内容显示在设备上之前更改它?例如:我有一个名叫John的用户订阅了一个名为food的主题,我向该主题发送了一个标题为"早上好用户名"的推送通知,但设备会显示"早上好John">
我想知道这在android或iOS上是否可行,以及是如何实现的
对于Android,是的,可以通过覆盖FirebaseMessagingService
的onMessageReceived
@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.
}
}