【发布时间】:2019-11-10 04:43:58
【问题描述】:
我添加了一个 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());
}
}
}
没有错误信息:
实际结果:通知永远不会到达前台。 预期结果:我希望在应用程序中时收到通知,而不仅仅是最小化时。
【问题讨论】:
标签: java android firebase-cloud-messaging