Added in API level 29

Builder

class Builder
kotlin.Any
   ↳ android.app.Notification.BubbleMetadata.Builder

Builder to construct a BubbleMetadata object.

Summary

Public constructors

Builder(shortcutId: String)

Creates a BubbleMetadata.Builder based on a ShortcutInfo.

Builder(intent: PendingIntent, icon: Icon)

Creates a BubbleMetadata.Builder based on the provided intent and icon.

Public methods
Notification.BubbleMetadata

Creates the BubbleMetadata defined by this builder.

Notification.BubbleMetadata.Builder

Sets whether the bubble will be posted in its expanded state.

Notification.BubbleMetadata.Builder

Sets an intent to send when this bubble is explicitly removed by the user.

Notification.BubbleMetadata.Builder

Sets the desired height in DPs for the expanded content of the bubble.

Notification.BubbleMetadata.Builder
setDesiredHeightResId(heightResId: Int)

Sets the desired height via resId for the expanded content of the bubble.

Notification.BubbleMetadata.Builder
setIcon(icon: Icon)

Sets the icon for the bubble.

Notification.BubbleMetadata.Builder

Sets the intent for the bubble.

Notification.BubbleMetadata.Builder
setSuppressNotification(shouldSuppressNotif: Boolean)

Sets whether the bubble will be posted without the associated notification in the notification shade.

Notification.BubbleMetadata.Builder
setSuppressableBubble(suppressBubble: Boolean)

Indicates whether the bubble should be visually suppressed from the bubble stack if the user is viewing the same content outside of the bubble.

Public constructors

Builder

Added in API level 29
Builder()

Deprecated: use Builder#Builder(String) for a bubble created via a ShortcutInfo or Builder#Builder(PendingIntent, Icon) for a bubble created via a PendingIntent.

Builder

Added in API level 29
Builder(shortcutId: String)

Creates a BubbleMetadata.Builder based on a ShortcutInfo. To create a shortcut bubble, ensure that the shortcut associated with the provided {@param shortcutId} is published as a dynamic shortcut that was built with ShortcutInfo.Builder#setLongLived(boolean) being true, otherwise your notification will not be able to bubble.

The shortcut icon will be used to represent the bubble when it is collapsed.

The shortcut activity will be used when the bubble is expanded. This will display the shortcut activity in a floating window over the existing foreground activity.

When the activity is launched from a bubble, Activity#isLaunchedFromBubble() will return with true.

If the shortcut has not been published when the bubble notification is sent, no bubble will be produced. If the shortcut is deleted while the bubble is active, the bubble will be removed.

Parameters
shortcutId String: This value cannot be null.
Exceptions
java.lang.NullPointerException if shortcutId is null.

Builder

Added in API level 29
Builder(
    intent: PendingIntent,
    icon: Icon)

Creates a BubbleMetadata.Builder based on the provided intent and icon.

The icon will be used to represent the bubble when it is collapsed. An icon should be representative of the content within the bubble. If your app produces multiple bubbles, the icon should be unique for each of them.

The intent that will be used when the bubble is expanded. This will display the app content in a floating window over the existing foreground activity. The intent should point to a resizable activity.

When the activity is launched from a bubble, Activity#isLaunchedFromBubble() will return with true.

Note that the pending intent used here requires PendingIntent.FLAG_MUTABLE.
Parameters
intent PendingIntent: This value cannot be null.
icon Icon: This value cannot be null.
Exceptions
java.lang.NullPointerException if icon is null.

Public methods

build

Added in API level 29
fun build(): Notification.BubbleMetadata

Creates the BubbleMetadata defined by this builder.

Return
Notification.BubbleMetadata This value cannot be null.
Exceptions
java.lang.NullPointerException if required elements have not been set.

setAutoExpandBubble

Added in API level 29
fun setAutoExpandBubble(shouldExpand: Boolean): Notification.BubbleMetadata.Builder

Sets whether the bubble will be posted in its expanded state.

This flag has no effect if the app posting the bubble is not in the foreground. The app is considered foreground if it is visible and on the screen, note that a foreground service does not qualify.

Generally, this flag should only be set if the user has performed an action to request or create a bubble.

Setting this flag is optional; it defaults to false.

Return
Notification.BubbleMetadata.Builder This value cannot be null.

setDeleteIntent

Added in API level 29
fun setDeleteIntent(deleteIntent: PendingIntent?): Notification.BubbleMetadata.Builder

Sets an intent to send when this bubble is explicitly removed by the user.

Setting a delete intent is optional.

Parameters
deleteIntent PendingIntent?: This value may be null.
Return
Notification.BubbleMetadata.Builder This value cannot be null.

setDesiredHeight

Added in API level 29
fun setDesiredHeight(height: Int): Notification.BubbleMetadata.Builder

Sets the desired height in DPs for the expanded content of the bubble.

This height may not be respected if there is not enough space on the screen or if the provided height is too small to be useful.

If setDesiredHeightResId(int) was previously called on this builder, the previous value set will be cleared after calling this method, and this value will be used instead.

A desired height (in DPs or via resID) is optional.

Return
Notification.BubbleMetadata.Builder This value cannot be null.

setDesiredHeightResId

Added in API level 29
fun setDesiredHeightResId(heightResId: Int): Notification.BubbleMetadata.Builder

Sets the desired height via resId for the expanded content of the bubble.

This height may not be respected if there is not enough space on the screen or if the provided height is too small to be useful.

If setDesiredHeight(int) was previously called on this builder, the previous value set will be cleared after calling this method, and this value will be used instead.

A desired height (in DPs or via resID) is optional.

Return
Notification.BubbleMetadata.Builder This value cannot be null.

setIcon

Added in API level 29
fun setIcon(icon: Icon): Notification.BubbleMetadata.Builder

Sets the icon for the bubble. Can only be used if the bubble was created via Builder#Builder(PendingIntent, Icon).

The icon will be used to represent the bubble when it is collapsed. An icon should be representative of the content within the bubble. If your app produces multiple bubbles, the icon should be unique for each of them.

It is recommended to use an Icon of type Icon#TYPE_URI or Icon#TYPE_URI_ADAPTIVE_BITMAP

Parameters
icon Icon: This value cannot be null.
Return
Notification.BubbleMetadata.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if icon is null.
java.lang.IllegalStateException if this builder was created via Builder#Builder(String).

setIntent

Added in API level 29
fun setIntent(intent: PendingIntent): Notification.BubbleMetadata.Builder

Sets the intent for the bubble.

The intent that will be used when the bubble is expanded. This will display the app content in a floating window over the existing foreground activity. The intent should point to a resizable activity.

Parameters
intent PendingIntent: This value cannot be null.
Return
Notification.BubbleMetadata.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if intent is null.
java.lang.IllegalStateException if this builder was created via Builder#Builder(String).

setSuppressNotification

Added in API level 29
fun setSuppressNotification(shouldSuppressNotif: Boolean): Notification.BubbleMetadata.Builder

Sets whether the bubble will be posted without the associated notification in the notification shade.

Generally, this flag should only be set if the user has performed an action to request or create a bubble, or if the user has seen the content in the notification and the notification is no longer relevant.

Setting this flag is optional; it defaults to false.

Return
Notification.BubbleMetadata.Builder This value cannot be null.

setSuppressableBubble

Added in API level 31
fun setSuppressableBubble(suppressBubble: Boolean): Notification.BubbleMetadata.Builder

Indicates whether the bubble should be visually suppressed from the bubble stack if the user is viewing the same content outside of the bubble. For example, the user has a bubble with Alice and then opens up the main app and navigates to Alice's page. To match the activity and the bubble notification, the bubble notification should have a locus id set that matches a locus id set on the activity. Notification.Builder#setLocusId(LocusId) Activity#setLocusContext(LocusId, Bundle)

Return
Notification.BubbleMetadata.Builder This value cannot be null.