有没有一种方法可以在通知显示在设备上之前更改通知内容?例如:我有一个名为John的用户订阅了一个名为food的主题,我向该主题发送推送通知并用标题“Good morning username”,但是设备将显示“Good morning John”。
我想知道在Android或iOS上是否可以实现以及如何实现。
有没有一种方法可以在通知显示在设备上之前更改通知内容?例如:我有一个名为John的用户订阅了一个名为food的主题,我向该主题发送推送通知并用标题“Good morning username”,但是设备将显示“Good morning 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.
}
}
FirebaseMessagingService
的onMessageReceived
方法吗? - glagarto