Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.slice:slice-view:1.0.0-rc01

SliceMetadata

public class SliceMetadata
extends Object

java.lang.Object
   ↳ androidx.slice.SliceMetadata


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

Summary

Constants

int LOADED_ALL

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

int LOADED_NONE

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

int LOADED_PARTIAL

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

Public methods

static SliceMetadata from(Context context, Slice slice)

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

long getExpiry()

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

int getHeaderType()
PendingIntent getInputRangeAction()

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

long getLastUpdatedTime()
int getLoadingState()
SliceAction getPrimaryAction()
Pair<Integer, Integer> getRange()

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

int getRangeValue()

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

List<SliceAction> getSliceActions()
List<String> getSliceKeywords()
CharSequence getSubtitle()
CharSequence getSummary()
CharSequence getTitle()
List<SliceAction> getToggles()
boolean hasLargeMode()
boolean isErrorSlice()

Indicates whether this slice indicates an error, i.e.

boolean isPermissionSlice()

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

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.

Inherited methods

Constants

LOADED_ALL

added in version 1.0.0
public static final int LOADED_ALL

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

Constant Value: 2 (0x00000002)

LOADED_NONE

added in version 1.0.0
public static final int LOADED_NONE

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

Constant Value: 0 (0x00000000)

LOADED_PARTIAL

added in version 1.0.0
public static final int LOADED_PARTIAL

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

Constant Value: 1 (0x00000001)

Public methods

from

added in version 1.0.0
public static SliceMetadata from (Context context, 
                Slice slice)

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 Slice: the slice to extract metadata from.

Returns
SliceMetadata the metadata associated with the provided slice.

getExpiry

added in version 1.0.0
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 ListBuilder.INFINITY if the slice is not time-sensitive.

getHeaderType

added in version 1.0.0
public int getHeaderType ()

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

getInputRangeAction

added in version 1.0.0
public PendingIntent getInputRangeAction ()

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

Returns
PendingIntent the PendingIntent for the input range.

getLastUpdatedTime

added in version 1.0.0
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 version 1.0.0
public int getLoadingState ()

Returns
int the current loading state for this slice.

getPrimaryAction

added in version 1.0.0
public SliceAction getPrimaryAction ()

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

getRange

added in version 1.0.0
public Pair<Integer, Integer> getRange ()

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

Returns
Pair<Integer, Integer> 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 version 1.0.0
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 version 1.0.0
public List<SliceAction> getSliceActions ()

Returns
List<SliceAction> the group of actions associated with this slice, if they exist.

getSliceKeywords

added in version 1.0.0
public List<String> getSliceKeywords ()

Returns
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 version 1.0.0
public CharSequence getSubtitle ()

Returns
CharSequence the subtitle associated with this slice, if it exists.

getSummary

added in version 1.0.0
public CharSequence getSummary ()

Returns
CharSequence the summary associated with this slice, if it exists.

getTitle

added in version 1.0.0
public CharSequence getTitle ()

Returns
CharSequence the title associated with this slice, if it exists.

getToggles

added in version 1.0.0
public List<SliceAction> getToggles ()

Returns
List<SliceAction> the toggles associated with the header of this slice.

hasLargeMode

added in version 1.0.0
public boolean hasLargeMode ()

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

isErrorSlice

added in version 1.0.0
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 version 1.0.0
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.

sendInputRangeAction

added in version 1.0.0
public boolean sendInputRangeAction (int newValue)

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.

Returns
boolean whether there was an action to send.

Throws
PendingIntent.CanceledException

sendToggleAction

added in version 1.0.0
public boolean sendToggleAction (SliceAction toggleAction, 
                boolean toggleValue)

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

Parameters
toggleAction SliceAction: the toggle action.

toggleValue boolean: the new value to set the toggle to.

Returns
boolean whether there was an action to send.

Throws
PendingIntent.CanceledException