我添加了一个FirebaseMessagingService类来接收前台通知。 我没有收到前台通知。 在后台最小化应用程序时,它可以正常工作。
我已经设置了具有Firebase功能的后台通知,并且可以正常工作,现在我正试图在前台获取此通知,但该通知没有出现。
我的FirebaseMessagingService类:
public class FirebaseMessaging extends FirebaseMessagingService {
@Override
public void onmessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onmessageReceived(remoteMessage);
if (remoteMessage.getNotification() != null) {
String notification_title = remoteMessage.getNotification().getTitle();
String notification_message = remoteMessage.getNotification().getBody();
Notification.Builder mBuilder = new Notification.Builder(this)
.setContentTitle(notification_title)
.setContentText(notification_message)
.setSmallIcon(R.drawable.default_avatar);
int mNotificationId = (int) System.currentTimeMillis();
Notificationmanager mNotifyMgr = (Notificationmanager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId,mBuilder.build());
}
}
}
没有错误消息:
实际结果:通知永远不会到达前台。 预期结果:我希望不仅在最小化时在应用程序中收到即时消息通知。