# NotificationCompat.BubbleMetadata.Builder

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/app/NotificationCompat.java+class:androidx.core.app.NotificationCompat.BubbleMetadata.Builder) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

*** ** * ** ***


```
public final class NotificationCompat.BubbleMetadata.Builder
```

<br />

*** ** * ** ***

Builder to construct a `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata` object.

## Summary

| ### Public constructors |
|---|
| `[Builder](https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder())()` **This method is deprecated.** use `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String)` for a bubble created via a `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat` or `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(android.app.PendingIntent,androidx.core.graphics.drawable.IconCompat)` for a bubble created via a `https://developer.android.com/reference/android/app/PendingIntent.html`. <br /> |
| `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html shortcutId)` Creates a `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` based on a `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat`. |
| `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(android.app.PendingIntent,androidx.core.graphics.drawable.IconCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/PendingIntent.html intent, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat icon)` Creates a `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` based on the provided intent and icon. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#build()()` Creates the `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setAutoExpandBubble(boolean)(boolean shouldExpand)` If set and the app creating the bubble is in the foreground, the bubble will be posted in its expanded state, with the contents of `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata#getIntent()` in a floating window. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setDeleteIntent(android.app.PendingIntent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html deleteIntent)` Sets an optional intent to send when this bubble is explicitly removed by the user. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setDesiredHeight(int)(@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) int height)` Sets the desired height in DPs for the app content defined by `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIntent(android.app.PendingIntent)`, 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. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setDesiredHeightResId(int)(@https://developer.android.com/reference/androidx/annotation/DimenRes int heightResId)` Sets the desired height via resId for the app content defined by `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIntent(android.app.PendingIntent)`, 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. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIcon(androidx.core.graphics.drawable.IconCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat icon)` Sets the icon for the bubble. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIntent(android.app.PendingIntent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/PendingIntent.html intent)` Sets the intent that will be used when the bubble is expanded. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` | `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setSuppressNotification(boolean)(boolean shouldSuppressNotif)` If set and the app posting the bubble is in the foreground, the bubble will be posted **without** the associated notification in the notification shade. |

## Public constructors

### Builder

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0) Deprecated in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
public [Builder](https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String)` for a bubble created via a `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat` or `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(android.app.PendingIntent,androidx.core.graphics.drawable.IconCompat)` for a bubble created via a `https://developer.android.com/reference/android/app/PendingIntent.html`.

### Builder

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
@RequiresApi(value = 30)
public Builder(@NonNull String shortcutId)
```

Creates a `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder` based on a `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat`. 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 `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat.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.

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 |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if shortcutId is null. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat` |   |
| `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLongLived(boolean)` |   |
| `https://developer.android.com/reference/android/content/pm/ShortcutManager.html#addDynamicShortcuts(java.util.List&lt;android.content.pm.ShortcutInfo&gt;)` |   |

### Builder

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
public Builder(@NonNull PendingIntent intent, @NonNull IconCompat icon)
```

Creates a `https://developer.android.com/reference/androidx/core/app/NotificationCompat.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.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if intent is null. |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if icon is null. |

## Public methods

### build

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata build()
```

Creates the `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata` defined by this builder.

Will throw `https://developer.android.com/reference/java/lang/NullPointerException.html` if required fields have not been set on this builder.

### setAutoExpandBubble

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setAutoExpandBubble(boolean shouldExpand)
```

If set and the app creating the bubble is in the foreground, the bubble will be posted in its expanded state, with the contents of `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata#getIntent()` in a floating window.

If the app creating the bubble is not in the foreground this flag has no effect.

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

### setDeleteIntent

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setDeleteIntent(@Nullable PendingIntent deleteIntent)
```

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

### setDesiredHeight

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setDesiredHeight(@Dimension(unit = 0) int height)
```

Sets the desired height in DPs for the app content defined by `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIntent(android.app.PendingIntent)`, 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 `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#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.

### setDesiredHeightResId

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int heightResId)
```

Sets the desired height via resId for the app content defined by `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIntent(android.app.PendingIntent)`, 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 `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#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.

### setIcon

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setIcon(@NonNull IconCompat icon)
```

Sets the icon for the bubble. Can only be used if the bubble was created via `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(android.app.PendingIntent,androidx.core.graphics.drawable.IconCompat)`.

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 `https://developer.android.com/reference/android/graphics/drawable/Icon.html` of type `https://developer.android.com/reference/android/graphics/drawable/Icon.html#TYPE_URI` or `https://developer.android.com/reference/android/graphics/drawable/Icon.html#TYPE_URI_ADAPTIVE_BITMAP`

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if icon is null. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if this builder was created via `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String)`. |

### setIntent

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setIntent(@NonNull PendingIntent intent)
```

Sets 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.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if intent is null. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if this builder was created via `https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String)`. |

### setSuppressNotification

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
public @NonNull NotificationCompat.BubbleMetadata.Builder setSuppressNotification(boolean shouldSuppressNotif)
```

If set and the app posting the bubble is in the foreground, the bubble will be posted **without** the associated notification in the notification shade.

If the app posting the bubble is not in the foreground this flag has no effect.

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.