【发布时间】:2018-03-20 10:14:02
【问题描述】:
我在 FCM 消息服务的 onMessageReceived 中实现了以下代码,以便在应用处于前台时向用户显示通知。
通知已成功提出并正确显示在托盘中。 但是,我的要求是,当应用程序处于前台时,通知托盘会在前面几秒钟,然后它必须默认隐藏。如何做到这一点?
NotificationCompat.Builder notificationBuilder = new
NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notifications_black_24dp)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(2 , notificationBuilder.build());
谢谢
【问题讨论】:
-
这个答案对你有帮助吗!?
标签: android firebase-cloud-messaging android-notifications android-notification-bar