[英]Notification not showing when app is in foreground
我在扩展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);
但是,当应用程序在前台时通知不起作用,但仅当应用程序在后台时才起作用。
在AndroidManifest.xml
使用此权限:
<service android:name="com.codb.shoppingapp.utils.FirebaseNotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSANGING_EVENT" />
</intent-filter>
</service>
尝试在通知上设置通知频道 ID。 Android O 需要通知渠道。如果您忽略它,通知将不会显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.