是否可以在通知内容显示在设备上之前对其进行更改?例如:我有一个名为John的用户,该用户订阅了一个名为food的主题,我向该主题发送了带有标题为“ Good morning username”的推送通知,但设备将显示“ Good morning John”
我想知道这在Android或iOS上是否可行,以及如何实现
答案 0 :(得分:1)
对于 Android ,
是的,可以通过覆盖onMessageReceived
中的FirebaseMessagingService
@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.
}
}