【发布时间】:2017-01-01 23:51:06
【问题描述】:
我正在使用 NotificationCompat v7 来构建通知。我希望它有一个公开版本,锁屏信息较少,而私人版本则在手机解锁时提供更多通知列表信息。 android 开发人员文档中的说明非常简单......但它们对我不起作用。我一直得到私人版本,即使在锁定屏幕上也是如此。
谁能告诉我我做错了什么?
我在三星 Galaxy S6 上运行 android 版本 6.0.1,对于通知的私人版本,我正在通过 RemoteViews 类设置自定义视图。
这是我的代码:
NotificationCompat.Builder publicNotificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setContentTitle(expense.name)
.setContentText(expense.amount)
.setAutoCancel(true)
.setSmallIcon(R.drawable.wally_icon)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setSmallIcon(R.drawable.wally_icon)
.setContent(remoteViews)
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.setPublicVersion(publicNotificationBuilder.build())
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
notificationManager.notify((int)expense.id, notificationBuilder.build());
【问题讨论】:
-
公开通知仅适用于安全锁屏,即需要图案或别针的锁屏,您的锁屏了吗?
-
我的必须用我的指纹解锁,但我原以为这会算作锁屏。
-
FWIW, this sample app of mine 似乎工作正常,尽管我没有在锁屏上设置指纹锁的设备。我看到的最大区别是
RemoteViews。我不认为这会把事情搞砸,但我不能排除它。 -
呃,谢谢,但我尝试删除
setContent并改用标准标题和文本,我尝试像您的示例一样恢复到 NotificationCompat 的 v4,确保为两者设置了内容意图公共和私有,也从您的示例中复制了setDefaults方法,并尝试将公共通知的可见性明确声明为 NotificationCompat.VISIBILITY_PUBLIC,但似乎没有任何效果。我总是在锁定屏幕上收到私人通知:( -
我遇到了一些麻烦。摆弄了一个小时后,我意识到我必须在设备中设置通知设置以“隐藏敏感内容”。它可能与您的问题无关,但可能会帮助可能登陆这里并遇到与我类似问题的人。它也适用于
RemoteViews的通知。
标签: java android android-notifications