【问题标题】:Expandable Lockscreen Notification?可扩展的锁屏通知?
【发布时间】:2016-05-13 16:49:54
【问题描述】:

在 Android 6 上,我尝试显示具有以下属性组合的通知:

  1. 文字标题和内容
  2. 可扩展的图片内容(见herehere
  3. 不要在状态栏中显示通知图标(不想弄乱它)
  4. 不要让任何 LED 闪烁(不想给用户带来麻烦)
  5. 在锁屏上显示
  6. 以展开(或至少可展开)格式在锁屏上显示(显示 bigContentView)

我可以通过setPriority(Notification.PRIORITY_MIN) 实现 3 和 4,但是通知似乎根本没有显示在锁定屏幕上(5 失败)。

至于 6,当通知确实显示在锁屏上时,例如使用PRIORITY_MAX(通过 5 但在 3 和 4 上失败),它不可扩展甚至可扩展(在 6 上失败)。

我正在使用以下设置通知:

Notification notification = new NotificationCompat.Builder(context)
        .setContentTitle(titleText)
        .setContentText(contentText)
        .setSmallIcon(R.drawable.small_icon)
        .setOngoing(true)
        .setPriority(Notification.PRIORITY_DEFAULT)
        .setVisibility(Notification.VISIBILITY_PUBLIC)
        .build();

        // add the image content (via a remoteViews)...
        notification.bigContentView = remoteViews;
        notificationManager.notify(tag, id, notification);

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    .setContentView(RemoteViews views)

    远程视图 - 描述可以在另一个进程中显示的视图层次结构的类。层次结构是从一个布局资源文件膨胀而来的,这个类提供了一些基本的操作来修改膨胀层次结构的内容。

    编辑:

    稍后调用 .build()。

    Notification notification = new NotificationCompat.Builder(context)
            .setContentTitle(titleText)
            .setContentText(contentText)
            .setSmallIcon(R.drawable.small_icon)
            .setOngoing(true)
            .setPriority(Notification.PRIORITY_DEFAULT)
            .setVisibility(Notification.VISIBILITY_PUBLIC);
    
            // add the image content (via a remoteViews)...
            notification.bigContentView = remoteViews;
            notificationManager.notify(tag, id, notification.build());
    

    【讨论】:

    • 除了将.build() 移到以后,您还有什么其他建议吗?通知目前工作正常,当不在锁屏时......即通知出现,当您向下滑动查看通知时,您可以展开它以查看内容。真正缺少的是仍然在锁屏中查看扩展内容的能力...我什至不知道这是否可能?而且,最好在锁屏中看到它,但在状态栏中
    • 提出了两个建议,很抱歉沟通不畅。 1) 对构建器使用 .setContentViews 方法。 2)在添加内容视图后调用 .build() 。我将包含第三个想法 -> 具体阅读文档并按照本节所述进行操作:Applying an expanded layout to a notification
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    相关资源
    最近更新 更多