0

On Android 6 I'm trying to display a notification with the following combination of properties:

  1. text title and content
  2. expandable image content (see here and here)
  3. don't show a notification icon in the status bar (don't want to clutter it up)
  4. don't flash any LEDs (don't want to trouble user)
  5. show on lockscreen
  6. show on lockscreen in expanded (or at least expandable) format (showing the bigContentView)

I can achieve 3 and 4 by setPriority(Notification.PRIORITY_MIN) but then the notification doesn't seem to show on the lock screen at all (fail on 5).

As for 6, when the notification does shown on the lockscreen e.g. using PRIORITY_MAX (passing on 5 but failing on 3 and 4), it is not expanded or even expandable (failing on 6).

I'm using the following to set up the notification:

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);
Community
  • 1
  • 1
drmrbrewer
  • 11,491
  • 21
  • 85
  • 181

1 Answers1

0

.setContentView(RemoteViews views)

RemoteViews - A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.

Edit:

Call .build() later on.

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());
apelsoczi
  • 1,102
  • 8
  • 11
  • are you suggesting anything different other that moving `.build()` to later? The notification works just fine at the moment as it is, when not in lockscreen... i.e. the notification appears, and when you swipe down to view the notification, you can then expand it to see the content. what is really missing is the ability to see the expanded content **whilst still in the lockscreen**... I don't even know if that is possible? And, would be best to see it in the lockscreen but *not* in the status bar. – drmrbrewer May 13 '16 at 19:00
  • two suggestions were made, sorry for miscommunication. 1) use the .setContentViews method with the builder. 2) call .build() after the contentview is added. I'll include a 3rd thought -> read the documentation specifically and do as this section says: [Applying an expanded layout to a notification](http://developer.android.com/guide/topics/ui/notifiers/notifications.html#ApplyStyle) – apelsoczi May 13 '16 at 19:30