从https://material.io/guidelines/patterns/notifications.html#notifications-behavior,我真的能够通知用户,而无需显示通知。
我想在状态栏中显示一个闪烁的喜欢图标,而不会弹出通知查看。(如果您观看 From https://material.io/guidelines/patterns/notifications.html#notifications-behavior部分下的第一个视频,您可以看到状态栏中的闪烁)
但是,我不完全确定如何实现这一目标。每当我通知用户时,都会有一个通知弹出窗口。
我的代码如下
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());
Run Code Online (Sandbox Code Playgroud)
我想知道,当我的应用程序处于前台时,如何避免通知弹出窗口偷看,但只在状态栏中显示一个闪烁的图标。
| 归档时间: |
|
| 查看次数: |
807 次 |
| 最近记录: |