当应用程序在前台时避免通知弹出窗口预览

4

https://material.io/guidelines/patterns/notifications.html#notifications-behavior得知,我们可以在不显示通知弹出窗口的情况下通知用户。

我想在状态栏中显示一个闪烁的心形图标,而不是弹出通知窗口。 (如果您观看https://material.io/guidelines/patterns/notifications.html#notifications-behavior下第一个视频,您会看到状态栏中的闪烁)

状态栏中的闪烁图标

enter image description here

然而,我不确定如何实现这一点。每当我通知用户时,都会弹出通知弹出窗口。

通知弹出窗口

enter image description here

我的代码如下:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext(), org.yccheok.notification.Utils.createNotificationChannel())
    .setContentIntent(pendingIntent)
    .setSmallIcon(R.drawable.ic_notification)
    .setContentTitle(contentTitle)
    .setTicker(ticker)
    .setColorized(true)
    .setColor(context.getResources().getColor(R.color.accent_material_light))
    .setContentText(contentText);

mBuilder.setSound(Uri.parse(getStockAlertSound()));

mBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

mBuilder.setAutoCancel(true);

// Need BIG view?
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle(contentTitle);
inboxStyle.setSummaryText(summaryText);
for (SpannableString notificationMessage : notificationMessages) {
    inboxStyle.addLine(notificationMessage);
}
mBuilder.setStyle(inboxStyle);

mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

我在想,当我的应用程序处于前台时,如何避免弹出通知,而只在状态栏中显示闪烁的图标。
1个回答

6
.setPriority(NotificationManager.IMPORTANCE_LOW)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接