# NotificationCompat.BubbleMetadata.Builder

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/app/NotificationCompat.BubbleMetadata.Builder "View this page in Java")

<br />

```
class NotificationCompat.BubbleMetadata.Builder
```

<br />

*** ** * ** ***

Builder to construct a[BubbleMetadata](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata)object.

## Summary

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

|                                                                  ### Public functions                                                                   |
|---------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [NotificationCompat.BubbleMetadata](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata)                 | [build](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#build())`()` Creates the[BubbleMetadata](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata)defined by this builder.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setAutoExpandBubble](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setAutoExpandBubble(boolean))`(shouldExpand: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` 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[getIntent](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata#getIntent())in a floating window.                                                                                                                                                               |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setDeleteIntent](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setDeleteIntent(android.app.PendingIntent))`(deleteIntent: `[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)`?)` Sets an optional intent to send when this bubble is explicitly removed by the user.                                                                                                                                                                                                                                                                                                                                               |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setDesiredHeight](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setDesiredHeight(int))`(height: @`[Dimension](https://developer.android.com/reference/kotlin/androidx/annotation/Dimension)`(unit = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the desired height in DPs for the app content defined by[setIntent](https://developer.android.com/reference/kotlin/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.       |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setDesiredHeightResId](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setDesiredHeightResId(int))`(heightResId: @`[DimenRes](https://developer.android.com/reference/kotlin/androidx/annotation/DimenRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the desired height via resId for the app content defined by[setIntent](https://developer.android.com/reference/kotlin/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. |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setIcon](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIcon(androidx.core.graphics.drawable.IconCompat))`(icon: `[IconCompat](https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat)`)` Sets the icon for the bubble.                                                                                                                                                                                                                                                                                                                                                                                             |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setIntent](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setIntent(android.app.PendingIntent))`(intent: `[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)`)` Sets the intent that will be used when the bubble is expanded.                                                                                                                                                                                                                                                                                                                                                                                       |
| [NotificationCompat.BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder) | [setSuppressNotification](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#setSuppressNotification(boolean))`(shouldSuppressNotif: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` 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)  

```
[Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder())()
```
| **This function is deprecated.**   
|
use[Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String))for a bubble created via a[ShortcutInfoCompat](https://developer.android.com/reference/kotlin/androidx/core/content/pm/ShortcutInfoCompat)or[Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(android.app.PendingIntent,androidx.core.graphics.drawable.IconCompat))for a bubble created via a[PendingIntent](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)
Builder(shortcutId: String)
```

Creates a[BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder)based on a[ShortcutInfoCompat](https://developer.android.com/reference/kotlin/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[setLongLived](https://developer.android.com/reference/kotlin/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                                                     |
|---------------------------------------------------------------------------------------------------------------|------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if shortcutId is null. |

|                                                                                     See also                                                                                      |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [ShortcutInfoCompat](https://developer.android.com/reference/kotlin/androidx/core/content/pm/ShortcutInfoCompat)                                                                  |   |
| [setLongLived](https://developer.android.com/reference/kotlin/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLongLived(boolean))                                          |   |
| [addDynamicShortcuts](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)  

```
Builder(intent: PendingIntent, icon: IconCompat)
```

Creates a[BubbleMetadata.Builder](https://developer.android.com/reference/kotlin/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                                                     |
|---------------------------------------------------------------------------------------------------------------|--------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if intent is null. |
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if icon is null.   |

## Public functions

### build

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

```
fun build(): NotificationCompat.BubbleMetadata
```

Creates the[BubbleMetadata](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata)defined by this builder.

Will throw[NullPointerException](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)  

```
fun setAutoExpandBubble(shouldExpand: Boolean): NotificationCompat.BubbleMetadata.Builder
```

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[getIntent](https://developer.android.com/reference/kotlin/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)  

```
fun setDeleteIntent(deleteIntent: PendingIntent?): NotificationCompat.BubbleMetadata.Builder
```

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)  

```
fun setDesiredHeight(height: @Dimension(unit = 0) Int): NotificationCompat.BubbleMetadata.Builder
```

Sets the desired height in DPs for the app content defined by[setIntent](https://developer.android.com/reference/kotlin/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[setDesiredHeightResId](https://developer.android.com/reference/kotlin/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)  

```
fun setDesiredHeightResId(heightResId: @DimenRes Int): NotificationCompat.BubbleMetadata.Builder
```

Sets the desired height via resId for the app content defined by[setIntent](https://developer.android.com/reference/kotlin/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[setDesiredHeight](https://developer.android.com/reference/kotlin/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)  

```
fun setIcon(icon: IconCompat): NotificationCompat.BubbleMetadata.Builder
```

Sets the icon for the bubble. Can only be used if the bubble was created via[Builder](https://developer.android.com/reference/kotlin/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[Icon](https://developer.android.com/reference/android/graphics/drawable/Icon.html)of type[TYPE_URI](https://developer.android.com/reference/android/graphics/drawable/Icon.html#TYPE_URI())or[TYPE_URI_ADAPTIVE_BITMAP](https://developer.android.com/reference/android/graphics/drawable/Icon.html#TYPE_URI_ADAPTIVE_BITMAP())  

|                                                     Throws                                                      |
|-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)   | if icon is null.                                                                                                                                                                |
| [java.lang.IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if this builder was created via[Builder](https://developer.android.com/reference/kotlin/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)  

```
fun setIntent(intent: PendingIntent): NotificationCompat.BubbleMetadata.Builder
```

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                                                      |
|-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)   | if intent is null.                                                                                                                                                              |
| [java.lang.IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if this builder was created via[Builder](https://developer.android.com/reference/kotlin/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)  

```
fun setSuppressNotification(shouldSuppressNotif: Boolean): NotificationCompat.BubbleMetadata.Builder
```

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.