NotificationCompat.DecoratedCustomViewStyle

Added in 1.1.0

public class NotificationCompat.DecoratedCustomViewStyle extends NotificationCompat.Style


Notification style for custom views that are decorated by the system.

Instead of providing a notification that is completely custom, a developer can set this style and still obtain system decorations like the notification header with the expand affordance and actions.

Use setCustomContentView, setCustomBigContentView and setCustomHeadsUpContentView to set the corresponding custom views to display.

To use this style with your Notification, feed it to setStyle like so:

Notification noti = new NotificationCompat.Builder()
    .setSmallIcon(R.drawable.ic_stat_player)
    .setLargeIcon(albumArtBitmap))
    .setCustomContentView(contentView)
    .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
    .build();

If you are using this style, consider using the corresponding styles like TextAppearance_Compat_Notification or TextAppearance_Compat_Notification_Title in your custom views in order to get the correct styling on each platform version.

Summary

Public constructors

Public methods

static @NonNull List<CharSequence>
@RequiresApi(value = 24)
getTextsFromContentView(
    @NonNull Context context,
    @NonNull Notification notification
)

A helper method to get texts from a Notification's custom content view made by either setCustomBigContentView, setCustomContentView or setCustomHeadsUpContentView.

Inherited methods

From androidx.core.app.NotificationCompat.Style
@Nullable Notification

If this Style object has been set on a notification builder, this method will build that notification and return it.

void

Link this rich notification style with a notification builder.

Public constructors

DecoratedCustomViewStyle

Added in 1.1.0
public DecoratedCustomViewStyle()

Public methods

getTextsFromContentView

Added in 1.15.0-rc01
@RequiresApi(value = 24)
public static @NonNull List<CharSequencegetTextsFromContentView(
    @NonNull Context context,
    @NonNull Notification notification
)

A helper method to get texts from a Notification's custom content view made by either setCustomBigContentView, setCustomContentView or setCustomHeadsUpContentView. Note that this method will not look for publicVersion made by setPublicVersion.

Parameters
@NonNull Context context

A Context that will be used to inflate the content view from the notification.

@NonNull Notification notification

The notification from which to get texts from its content view.

Returns
@NonNull List<CharSequence>

A list of text from the notification custom content view made by the above method. Note that the method only returns a list of text from one of the custom view as the above when it set, meaning when multiple custom content views has set in a notification, the returned list will base on the detail of custom content and usage as the priority: First is bigContentView, then is contentView when no big content view has set, or headsUpContentView when set. Otherwise, returns the empty list.