可扩展的锁屏通知?

时间:2016-05-13 16:49:55

标签: android notifications

在Android 6上,我尝试使用以下属性组合显示通知:

  1. 文字标题和内容
  2. 可展开的图片内容(请参阅herehere
  3. 不要在状态栏中显示通知图标(不要让它混乱)
  4. 不要闪烁任何LED(不要让用户遇到麻烦)
  5. 在锁屏上显示
  6. 以扩展(或至少可扩展)格式在锁屏上显示(显示bigContentView)
  7. 我可以通过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);
    

1 个答案:

答案 0 :(得分:0)

.setContentView(RemoteViews views)

<强> RemoteViews - 描述可以在另一个进程中显示的视图层次结构的类。层次结构从布局资源文件中膨胀,此类提供一些用于修改膨胀层次结构内容的基本操作。

编辑:

稍后调用.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());