我正在使用v7的NotificationCompat构建通知。我希望它有一个公共版本,锁屏时显示较少的信息,并且有一个私人版本,在手机解锁时可以查看更多信息的通知列表中可用。 Android开发文档中的说明非常简单明了...但是它们对我不起作用。我总是得到私人版本,即使在锁定屏幕上也是如此。
请问有谁能告诉我我做错了什么吗?
我在我的三星Galaxy S6上运行Android 6.0.1,并且对于我的通知的私人版本,我通过RemoteViews类设置了一个自定义视图。
这是我的代码:
请问有谁能告诉我我做错了什么吗?
我在我的三星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());
RemoteViews
。我不认为它会弄乱事情,但我不能排除这种可能。 - CommonsWaresetContent
并改用标准的标题和文本,我尝试回滚到NotificationCompat的v4版本,就像您的示例一样,确保为公共和私有设置了内容意图,也从您的示例中复制了setDefaults
方法,并尝试显式声明公共通知的可见性为NotificationCompat.VISIBILITY_PUBLIC,但似乎没有任何作用。我总是在锁屏上收到私人通知:( - SnoopDouggRemoteViews
的通知。 - Supreethks