Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

SliceMetadata

open class SliceMetadata
kotlin.Any
   ↳ androidx.slice.SliceMetadata

Utility class to parse a Slice and provide access to information around its contents.

Summary

Constants

static Int

Indicates this slice has fully loaded and is not waiting for other content.

static Int

Indicates this slice is empty and waiting for content to be loaded.

static Int

Indicates this slice has some content but is waiting for other content to be loaded.

Public methods

open static SliceMetadata!
from(@NonNull context: Context, @NonNull slice: Slice)

Create a SliceMetadata object to provide access to some information around the slice and its contents.

open Long

A slice contains an expiry to indicate when the content in the slice might no longer be valid.

open Int

open PendingIntent?

Gets the input range action associated with the header of this slice, if it exists.

open Long

open Int

open SliceAction?

open Pair<Int!, Int!>?

Gets the range information associated with a progress bar or input range associated with this slice, if it exists.

open Int

Gets the current value for a progress bar or input range associated with this slice, if it exists, -1 if unknown.

open MutableList<SliceAction!>?

open MutableList<String!>?

open CharSequence?

open CharSequence?

open CharSequence?

open MutableList<SliceAction!>!

open Boolean

open Boolean

Indicates whether this slice was created using SliceUtils#parseSlice or through normal binding.

open Boolean

Indicates whether this slice indicates an error, i.

open Boolean

To present a slice from another app, the app must grant uri permissions for the slice.

open Boolean

open Boolean

Sends the intent to adjust the input range value for the header of this slice, if it exists.

open Boolean
sendToggleAction(toggleAction: SliceAction!, toggleValue: Boolean)

Sends the intent to adjust the state of the provided toggle action.

Constants

LOADED_ALL

static val LOADED_ALL: Int

Indicates this slice has fully loaded and is not waiting for other content.

Value: 2

LOADED_NONE

static val LOADED_NONE: Int

Indicates this slice is empty and waiting for content to be loaded.

Value: 0

LOADED_PARTIAL

static val LOADED_PARTIAL: Int

Indicates this slice has some content but is waiting for other content to be loaded.

Value: 1

Public methods

from

open static fun from(@NonNull context: Context, @NonNull slice: Slice): SliceMetadata!

Create a SliceMetadata object to provide access to some information around the slice and its contents.

Parameters
context Context: the context to use for the slice.
slice Context: the slice to extract metadata from.
Return
SliceMetadata!: the metadata associated with the provided slice.

getExpiry

open fun getExpiry(): Long

A slice contains an expiry to indicate when the content in the slice might no longer be valid.

Return
Long: the time, measured in milliseconds, between the expiry time of this slice and midnight, January 1, 1970 UTC, or androidx.slice.builders.ListBuilder#INFINITY if the slice is not time-sensitive.

getHeaderType

open fun getHeaderType(): Int
Return
Int: the type of row that is used for the header of this slice, -1 if unknown.

getInputRangeAction

@Nullable open fun getInputRangeAction(): PendingIntent?

Gets the input range action associated with the header of this slice, if it exists.

Return
PendingIntent?: the android.app.PendingIntent for the input range.

getLastUpdatedTime

open fun getLastUpdatedTime(): Long
Return
Long: the time, measured in milliseconds, between when the slice was created or last updated, and midnight, January 1, 1970 UTC.

getLoadingState

open fun getLoadingState(): Int
Return
Int: the current loading state for this slice.

getPrimaryAction

@Nullable open fun getPrimaryAction(): SliceAction?
Return
SliceAction?: the primary action for this slice, null if none specified.

getRange

@Nullable open fun getRange(): Pair<Int!, Int!>?

Gets the range information associated with a progress bar or input range associated with this slice, if it exists.

Return
Pair<Int!, Int!>?: a pair where the first item is the minimum value of the range and the second item is the maximum value of the range.

getRangeValue

@NonNull open fun getRangeValue(): Int

Gets the current value for a progress bar or input range associated with this slice, if it exists, -1 if unknown.

Return
Int: the current value of a progress bar or input range associated with this slice.

getSliceActions

@Nullable open fun getSliceActions(): MutableList<SliceAction!>?
Return
MutableList<SliceAction!>?: the group of actions associated with this slice, if they exist.

getSliceKeywords

@Nullable open fun getSliceKeywords(): MutableList<String!>?
Return
MutableList<String!>?: the list of keywords associated with the provided slice, null if no keywords were specified or an empty list if the slice was specified to have no keywords.

getSubtitle

@Nullable open fun getSubtitle(): CharSequence?
Return
CharSequence?: the subtitle associated with this slice, if it exists.

getSummary

@Nullable open fun getSummary(): CharSequence?
Return
CharSequence?: the summary associated with this slice, if it exists.

getTitle

@Nullable open fun getTitle(): CharSequence?
Return
CharSequence?: the title associated with this slice, if it exists.

getToggles

open fun getToggles(): MutableList<SliceAction!>!
Return
MutableList<SliceAction!>!: the toggles associated with the header of this slice.

hasLargeMode

open fun hasLargeMode(): Boolean
Return
Boolean: whether this slice has content to show when presented in SliceView#MODE_LARGE.

isCachedSlice

open fun isCachedSlice(): Boolean

Indicates whether this slice was created using SliceUtils#parseSlice or through normal binding.

isErrorSlice

open fun isErrorSlice(): Boolean

Indicates whether this slice indicates an error, i.e. the normal contents of this slice are unavailable and instead the slice contains a message indicating an error.

Return
Boolean: whether this slice represents an error.

isPermissionSlice

open fun isPermissionSlice(): Boolean

To present a slice from another app, the app must grant uri permissions for the slice. If these permissions have not been granted and the app slice is requested then a permission request slice will be returned instead, allowing the user to grant permission. This method can be used to identify if a slice is a permission request.

Return
Boolean: whether this slice represents a permission request.

isSelection

open fun isSelection(): Boolean
Return
Boolean: whether this slice is a selection (a drop-down list) slice.

sendInputRangeAction

open fun sendInputRangeAction(newValue: Int): Boolean

Sends the intent to adjust the input range value for the header of this slice, if it exists.

Parameters
newValue Int: the value to set the input range to.
Return
Boolean: whether there was an action to send.

sendToggleAction

open fun sendToggleAction(toggleAction: SliceAction!, toggleValue: Boolean): Boolean

Sends the intent to adjust the state of the provided toggle action.

Parameters
toggleAction SliceAction!: the toggle action.
toggleValue SliceAction!: the new value to set the toggle to.
Return
Boolean: whether there was an action to send.