NotificationCompat.MetricStyle


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


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 setStyle like so:

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 Metric object to be valid; an invalid style will be rejected when build is called.

If a notification with this style is 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 setLargeIcon.

This style is only supported in devices with 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 Int

Special value for setCriticalMetric to indicate that none of the metrics should be considered the "most important" one.

Public constructors

@RequiresApi(value = 37)
MetricStyle()

Constructs a new instance of MetricStyle.

Public functions

Unit

This is called with the extras of the framework Notification during the build process, after apply() has been called.

NotificationCompat.MetricStyle

Adds a Metric to this MetricStyle.

Boolean
equals(obj: Any!)
NotificationCompat.Metric?

Returns which, if any, of the metrics is considered the "most important", or null if none are.

(Mutable)List<NotificationCompat.Metric!>

Returns an immutable view of the list of Metric instances in this MetricStyle.

Int
NotificationCompat.MetricStyle

Indicates which of the metrics is considered the "most important".

NotificationCompat.MetricStyle

Sets the list of Metric instances for this MetricStyle, replacing whatever was added before.

String

Protected functions

Unit
Unit

Inherited functions

From androidx.core.app.NotificationCompat.Style
Notification?

If this Style object has been set on a notification builder, this method will build that notification and return it.

Unit

Link this rich notification style with a notification builder.

Constants

METRIC_INDEX_NONE

const val METRIC_INDEX_NONE = -1: Int

Special value for setCriticalMetric to indicate that none of the metrics should be considered the "most important" one.

Public constructors

MetricStyle

@RequiresApi(value = 37)
MetricStyle()

Constructs a new instance of MetricStyle. Use addMetric to populate it.

This style is only supported in devices with 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

fun addCompatExtras(extras: Bundle): Unit

This is called with the extras of the framework Notification during the 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.

equals

fun equals(obj: Any!): Boolean

getCriticalMetric

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 setCriticalMetric has been set, the first metric in the list is considered the critical one.

getMetrics

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

Returns an immutable view of the list of Metric instances in this MetricStyle.

hashCode

fun hashCode(): Int

setCriticalMetric

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: Int

either the index (0-based) of an item in getMetrics, or METRIC_INDEX_NONE to indicate no Metric should be used for this purpose

setMetrics

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

Sets the list of Metric instances for this MetricStyle, replacing whatever was added before.

toString

fun toString(): String

Protected functions

clearCompatExtraKeys

protected fun clearCompatExtraKeys(extras: Bundle): Unit

restoreFromCompatExtras

protected fun restoreFromCompatExtras(extras: Bundle): Unit