Notification.BubbleMetadata.Builder

public static final class Notification.BubbleMetadata.Builder
extends Object

java.lang.Object
   ↳ android.app.Notification.BubbleMetadata.Builder


Builder to construct a BubbleMetadata object.

Summary

Public constructors

Builder()

This constructor is 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(String shortcutId)

Creates a BubbleMetadata.Builder based on a ShortcutInfo.

Builder(PendingIntent intent, Icon icon)

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

Public methods

Notification.BubbleMetadata build()

Creates the BubbleMetadata defined by this builder.

Notification.BubbleMetadata.Builder setAutoExpandBubble(boolean shouldExpand)

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

Notification.BubbleMetadata.Builder setDeleteIntent(PendingIntent deleteIntent)

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

Notification.BubbleMetadata.Builder setDesiredHeight(int height)

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

Notification.BubbleMetadata.Builder setDesiredHeightResId(int heightResId)

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 setIntent(PendingIntent intent)

Sets the intent for the bubble.

Notification.BubbleMetadata.Builder setSuppressNotification(boolean shouldSuppressNotif)

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

Notification.BubbleMetadata.Builder setSuppressableBubble(boolean suppressBubble)

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

Inherited methods

Public constructors

Builder

Added in API level 29
public Builder ()

This constructor is 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
public Builder (String shortcutId)

Creates a BubbleMetadata.Builder based on a ShortcutInfo. To create a shortcut bubble, ensure that the shortcut associated with the provided 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.

Throws
NullPointerException if shortcutId is null.

Builder

Added in API level 29
public Builder (PendingIntent intent, 
                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.

Throws
NullPointerException if intent is null.
NullPointerException if icon is null.

Public methods

build

Added in API level 29
public Notification.BubbleMetadata build ()

Creates the BubbleMetadata defined by this builder.

Returns
Notification.BubbleMetadata This value cannot be null.

Throws
NullPointerException if required elements have not been set.

setAutoExpandBubble

Added in API level 29
public Notification.BubbleMetadata.Builder setAutoExpandBubble (boolean shouldExpand)

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.

Parameters
shouldExpand boolean

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

setDeleteIntent

Added in API level 29
public Notification.BubbleMetadata.Builder setDeleteIntent (PendingIntent deleteIntent)

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.

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

setDesiredHeight

Added in API level 29
public Notification.BubbleMetadata.Builder setDesiredHeight (int height)

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.

Parameters
height int

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

setDesiredHeightResId

Added in API level 29
public Notification.BubbleMetadata.Builder setDesiredHeightResId (int heightResId)

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.

Parameters
heightResId int

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

setIcon

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

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.

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

Throws
NullPointerException if icon is null.
IllegalStateException if this builder was created via Builder#Builder(String).

setIntent

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

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.

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

Throws
NullPointerException if intent is null.
IllegalStateException if this builder was created via Builder#Builder(String).

setSuppressNotification

Added in API level 29
public Notification.BubbleMetadata.Builder setSuppressNotification (boolean shouldSuppressNotif)

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.

Parameters
shouldSuppressNotif boolean

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

setSuppressableBubble

Added in API level 31
public Notification.BubbleMetadata.Builder setSuppressableBubble (boolean suppressBubble)

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)

Parameters
suppressBubble boolean

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