# NotificationCompat.MetricStyle

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.MetricStyle) Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

*** ** * ** ***


```
@RequiresApi(value = 26)
class NotificationCompat.MetricStyle : NotificationCompat.Style
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.core.app.NotificationCompat.Style](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style) ||
|   | ↳ | [androidx.core.app.NotificationCompat.MetricStyle](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle) |

*** ** * ** ***

A notification style which shows up to 3 metrics when expanded. Metrics usually represent quantities that change over time, such as fitness information collected by a tracker, timers, weather information, etc.

To use this style with your Notification, feed it to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#setStyle(androidx.core.app.NotificationCompat.Style)` like so:

```kotlin
Notification notif = new NotificationCompat.Builder(context)
  .setStyle(new MetricStyle()
      .addMetric(new Metric(new Metric.FixedInt(1979), "Steps"))
      .addMetric(new Metric(
          Metric.TimeDifference.forStopwatch(startTime, FORMAT_CHRONOMETER_AUTOMATIC),
          "Time elapsed")))
```

A MetricStyle must contain at least one `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` object to be valid; an invalid style will be rejected when `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#build()` is called.

If a notification with this style is `https://developer.android.com/reference/android/app/Notification.html#FLAG_PROMOTED_ONGOING`, then one of its metrics might be displayed in the status bar chip.

Note that this style doesn't display the large icon set via `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#setLargeIcon(android.graphics.drawable.Icon)`.

This style is only supported in devices with `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#CINNAMON_BUN` or greater. If used on a device with a lower `SDK_INT` then the notification will be displayed with the standard appearance (i.e. showing content text, but *not* metrics).

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#METRIC_INDEX_NONE() = -1` Special value for `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#setCriticalMetric(int)` to indicate that none of the metrics should be considered the "most important" one. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#MetricStyle()()` Constructs a new instance of `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#addCompatExtras(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)` This is called with the extras of the framework `https://developer.android.com/reference/android/app/Notification.html` during the `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#build()` process, after `apply()` has been called. |
| `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#addMetric(androidx.core.app.NotificationCompat.Metric)(metric: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric)` Adds a `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` to this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#equals(java.lang.Object)(obj: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#getCriticalMetric()()` Returns which, if any, of the metrics is considered the "most important", or `null` if none are. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric!>` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#getMetrics()()` Returns an immutable view of the list of `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` instances in this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#hashCode()()` |
| `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#setCriticalMetric(int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Indicates which of the metrics is considered the "most important". |
| `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#setMetrics(java.util.List<androidx.core.app.NotificationCompat.Metric>)(metrics: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric!>)` Sets the list of `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` instances for this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`, replacing whatever was added before. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#toString()()` |

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#clearCompatExtraKeys(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#restoreFromCompatExtras(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)` |

### Inherited functions

From [androidx.core.app.NotificationCompat.Style](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style) `https://developer.android.com/reference/android/app/Notification.html?` `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style#build()()`

If this Style object has been set on a notification builder, this method will build that notification and return it.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style#setBuilder(androidx.core.app.NotificationCompat.Builder)(builder: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder?)`

Link this rich notification style with a notification builder.

## Constants

### METRIC_INDEX_NONE

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

```
const val METRIC_INDEX_NONE = -1: Int
```

Special value for `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#setCriticalMetric(int)` to indicate that none of the metrics should be considered the "most important" one.

## Public constructors

### MetricStyle

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

```
@RequiresApi(value = 37)
MetricStyle()
```

Constructs a new instance of `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`. Use `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#addMetric(androidx.core.app.NotificationCompat.Metric)` to populate it.

This style is only supported in devices with `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#CINNAMON_BUN` or greater. If used on a device with a lower `SDK_INT` then the notification will be displayed with the standard appearance (i.e. showing content text, but *not* metrics).

## Public functions

### addCompatExtras

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

```
fun addCompatExtras(extras: Bundle): Unit
```

This is called with the extras of the framework `https://developer.android.com/reference/android/app/Notification.html` during the `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#build()` process, after `apply()` has been called. This means that you only need to add data which won't be populated by the framework Notification which was built so far. Moreover, recovering builders and styles is only supported at API 19 and above, no implementation is required for current BigTextStyle, BigPictureStyle, or InboxStyle.

### addMetric

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

```
fun addMetric(metric: NotificationCompat.Metric): NotificationCompat.MetricStyle
```

Adds a `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` to this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`.

### equals

```
fun equals(obj: Any!): Boolean
```

### getCriticalMetric

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

```
fun getCriticalMetric(): NotificationCompat.Metric?
```

Returns which, if any, of the metrics is considered the "most important", or `null` if none are. This may be used when the notification is displayed in other surfaces (such as a status bar chip).

By default, unless `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#setCriticalMetric(int)` has been set, the first metric in the list is considered the critical one.

### getMetrics

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

```
fun getMetrics(): (Mutable)List<NotificationCompat.Metric!>
```

Returns an immutable view of the list of `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` instances in this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`.

### hashCode

```
fun hashCode(): Int
```

### setCriticalMetric

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

```
fun setCriticalMetric(index: Int): NotificationCompat.MetricStyle
```

Indicates which of the metrics is considered the "most important". This may be used when the notification is displayed in other surfaces (such as a status bar chip).

| Parameters |
|---|---|
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | either the index (0-based) of an item in `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#getMetrics()`, or `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle#METRIC_INDEX_NONE()` to indicate no `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` should be used for this purpose |

### setMetrics

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

```
fun setMetrics(metrics: (Mutable)List<NotificationCompat.Metric!>): NotificationCompat.MetricStyle
```

Sets the list of `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric` instances for this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.MetricStyle`, replacing whatever was added before.

### toString

```
fun toString(): String
```

## Protected functions

### clearCompatExtraKeys

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

```
protected fun clearCompatExtraKeys(extras: Bundle): Unit
```

### restoreFromCompatExtras

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

```
protected fun restoreFromCompatExtras(extras: Bundle): Unit
```