SliceMetadata


@RequiresApi(value = 19)
public class SliceMetadata


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

Summary

Constants

static final int

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

static final int

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

static final int

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

Public methods

static @NonNull SliceMetadata
from(@Nullable Context context, @NonNull Slice slice)

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

long

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

int
@NonNull Bundle
@Nullable PendingIntent

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

long
int
@Nullable SliceAction
@Nullable Pair<IntegerInteger>

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

int

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

@Nullable List<SliceAction>
@Nullable List<String>
@Nullable CharSequence
@Nullable CharSequence
@Nullable CharSequence
List<SliceAction>
boolean
boolean

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

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.

boolean

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

boolean
boolean
sendInputRangeAction(int newValue)

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

boolean
sendToggleAction(SliceAction toggleAction, boolean toggleValue)

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

Constants

LOADED_ALL

Added in 1.1.0-alpha02
public static final int LOADED_ALL = 2

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

LOADED_NONE

Added in 1.1.0-alpha02
public static final int LOADED_NONE = 0

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

LOADED_PARTIAL

Added in 1.1.0-alpha02
public static final int LOADED_PARTIAL = 1

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

Public methods

from

Added in 1.1.0-alpha02
public static @NonNull SliceMetadata from(@Nullable Context context, @NonNull Slice slice)

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

Parameters
@Nullable Context context

the context to use for the slice.

@NonNull Slice slice

the slice to extract metadata from.

Returns
@NonNull SliceMetadata

the metadata associated with the provided slice.

getExpiry

Added in 1.1.0-alpha02
public long getExpiry()

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

Returns
long

the time, measured in milliseconds, between the expiry time of this slice and midnight, January 1, 1970 UTC, or INFINITY if the slice is not time-sensitive.

getHeaderType

Added in 1.1.0-alpha02
public int getHeaderType()
Returns
int

the type of row that is used for the header of this slice, -1 if unknown.

getHostExtras

Added in 1.1.0-alpha02
public @NonNull Bundle getHostExtras()

getInputRangeAction

Added in 1.1.0-alpha02
public @Nullable PendingIntent getInputRangeAction()

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

Returns
@Nullable PendingIntent

the android.app.PendingIntent for the input range.

getLastUpdatedTime

Added in 1.1.0-alpha02
public long getLastUpdatedTime()
Returns
long

the time, measured in milliseconds, between when the slice was created or last updated, and midnight, January 1, 1970 UTC.

getLoadingState

Added in 1.1.0-alpha02
public int getLoadingState()
Returns
int

the current loading state for this slice.

getPrimaryAction

Added in 1.1.0-alpha02
public @Nullable SliceAction getPrimaryAction()
Returns
@Nullable SliceAction

the primary action for this slice, null if none specified.

getRange

Added in 1.1.0-alpha02
public @Nullable Pair<IntegerIntegergetRange()

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

Returns
@Nullable Pair<IntegerInteger>

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

Added in 1.1.0-alpha02
public int getRangeValue()

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

Returns
int

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

getSliceActions

Added in 1.1.0-alpha02
public @Nullable List<SliceActiongetSliceActions()
Returns
@Nullable List<SliceAction>

the group of actions associated with this slice, if they exist.

getSliceKeywords

Added in 1.1.0-alpha02
public @Nullable List<StringgetSliceKeywords()
Returns
@Nullable List<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

Added in 1.1.0-alpha02
public @Nullable CharSequence getSubtitle()
Returns
@Nullable CharSequence

the subtitle associated with this slice, if it exists.

getSummary

Added in 1.1.0-alpha02
public @Nullable CharSequence getSummary()
Returns
@Nullable CharSequence

the summary associated with this slice, if it exists.

getTitle

Added in 1.1.0-alpha02
public @Nullable CharSequence getTitle()
Returns
@Nullable CharSequence

the title associated with this slice, if it exists.

getToggles

Added in 1.1.0-alpha02
public List<SliceActiongetToggles()
Returns
List<SliceAction>

the toggles associated with the header of this slice.

hasLargeMode

Added in 1.1.0-alpha02
public boolean hasLargeMode()
Returns
boolean

whether this slice has content to show when presented in MODE_LARGE.

isCachedSlice

Added in 1.1.0-alpha02
public boolean isCachedSlice()

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

isErrorSlice

Added in 1.1.0-alpha02
public boolean isErrorSlice()

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.

Returns
boolean

whether this slice represents an error.

isPermissionSlice

Added in 1.1.0-alpha02
public boolean isPermissionSlice()

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.

Returns
boolean

whether this slice represents a permission request.

isSelection

Added in 1.1.0-alpha02
public boolean isSelection()
Returns
boolean

whether this slice is a selection (a drop-down list) slice.

sendInputRangeAction

Added in 1.1.0-alpha02
public boolean sendInputRangeAction(int newValue)

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

Parameters
int newValue

the value to set the input range to.

Returns
boolean

whether there was an action to send.

sendToggleAction

Added in 1.1.0-alpha02
public boolean sendToggleAction(SliceAction toggleAction, boolean toggleValue)

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

Parameters
SliceAction toggleAction

the toggle action.

boolean toggleValue

the new value to set the toggle to.

Returns
boolean

whether there was an action to send.