[英]Notification not showing when app is in foreground
I have added this code in the onMessageReceived
method of the FirebaseNotificationService
class which extends FirebaseMessagingService
我在扩展
FirebaseMessagingService
的FirebaseNotificationService
类的onMessageReceived
方法中添加了此代码
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setSmallIcon(R.mipmap.ic_launcher)
.build();
NotificationManagerCompat manager = NotificationManagerCompat.from(getApplicationContext());
manager.notify(123, notification);
But still, the notification isn't working when the app is in the foreground but works only when the app is in the background.但是,当应用程序在前台时通知不起作用,但仅当应用程序在后台时才起作用。
With this permission in AndroidManifest.xml
:在
AndroidManifest.xml
使用此权限:
<service android:name="com.codb.shoppingapp.utils.FirebaseNotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSANGING_EVENT" />
</intent-filter>
</service>
Try setting a notification channel id on the notification.尝试在通知上设置通知频道 ID。 Notification channels became required with Android O. If you leave it out, the notification will not show.
Android O 需要通知渠道。如果您忽略它,通知将不会显示。
https://developer.android.com/training/notify-user/channels https://developer.android.com/training/notify-user/channels
FCM has two messages types: when your app is in the background. FCM 有两种消息类型:当您的应用程序在后台时。
so, You should send a format is Data Message to handle notification in onMessageReceived when the app is background or foreground因此,当应用程序处于后台或前台时,您应该发送格式为数据消息以处理 onMessageReceived 中的通知
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.