Slice

public final class Slice
extends Object implements Parcelable

java.lang.Object
   ↳ android.app.slice.Slice


A slice is a piece of app content and actions that can be surfaced outside of the app.

They are constructed using Slice.Builder in a tree structure that provides the OS some information about how the content should be displayed.

Summary

Nested classes

class Slice.Builder

A Builder used to construct Slices  

Constants

String EXTRA_RANGE_VALUE

Key to retrieve an extra added to an intent when the value of an input range is changed.

String EXTRA_SLIDER_VALUE

This constant was deprecated in API level P. remove once support lib is update to use EXTRA_RANGE_VALUE instead

String EXTRA_TOGGLE_STATE

Key to retrieve an extra added to an intent when a control is changed.

String HINT_ACTIONS

Hint that this slice contains a number of actions that can be grouped together in a sort of controls area of the UI.

String HINT_ERROR

A hint to indicate that this slice represents an error.

String HINT_HORIZONTAL

Hint that list items within this slice or subslice would appear better if organized horizontally.

String HINT_KEYWORDS

A hint to indicate that the contents of this subslice represent a list of keywords related to the parent slice.

String HINT_LARGE

Hint that this content is important and should be larger when displayed if possible.

String HINT_LAST_UPDATED

Hint indicating an item representing when the content was created or last updated.

String HINT_LIST

Hint that all sub-items/sub-slices within this content should be considered to have HINT_LIST_ITEM.

String HINT_LIST_ITEM

Hint that this item is part of a list and should be formatted as if is part of a list.

String HINT_NO_TINT

Hint to indicate that this content should not be tinted.

String HINT_PARTIAL

Hint to indicate that this slice is incomplete and an update will be sent once loading is complete.

String HINT_PERMISSION_REQUEST

A hint to indicate that this slice represents a permission request for showing slices.

String HINT_SEE_MORE

A hint representing that this item should be used to indicate that there's more content associated with this slice.

String HINT_SELECTED

Hint indicating that this item (and its sub-items) are the current selection.

String HINT_SHORTCUT

Hint to indicate that this content should only be displayed if the slice is presented as a shortcut.

String HINT_SUMMARY

Hint indicating this content should be shown instead of the normal content when the slice is in small format.

String HINT_TITLE

Hint that this content is a title of other content in the slice.

String HINT_TTL

Hint indicating an item representing a time-to-live for the content.

String SUBTYPE_COLOR

Subtype to tag an item as representing a color.

String SUBTYPE_CONTENT_DESCRIPTION

Subtype to tag an item to use as a content description.

String SUBTYPE_LAYOUT_DIRECTION

Subtype to indicate that this item indicates the layout direction for content in the slice.

String SUBTYPE_MAX

Subtype to tag an item as representing the max int value for a SUBTYPE_RANGE.

String SUBTYPE_MESSAGE

Subtype to indicate that this is a message as part of a communication sequence in this slice.

String SUBTYPE_MILLIS

Subtype to tag an item as representing a time in milliseconds since midnight, January 1, 1970 UTC.

String SUBTYPE_PRIORITY

Subtype to tag an item representing priority.

String SUBTYPE_RANGE

Subtype to tag an item as representing a range.

String SUBTYPE_SLIDER

This constant was deprecated in API level P. remove once support lib is update to use SUBTYPE_RANGE instead

String SUBTYPE_SOURCE

Subtype to tag the source (i.e.

String SUBTYPE_TOGGLE

Subtype to indicate that this content has a toggle action associated with it.

String SUBTYPE_VALUE

Subtype to tag an item as representing the current int value for a SUBTYPE_RANGE.

Inherited constants

Fields

public static final Creator<Slice> CREATOR

Protected constructors

Slice(Parcel in)

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

List<String> getHints()
List<SliceItem> getItems()
SliceSpec getSpec()
Uri getUri()
boolean isCallerNeeded()

Returns whether the caller for this slice matters.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

EXTRA_RANGE_VALUE

String EXTRA_RANGE_VALUE

Key to retrieve an extra added to an intent when the value of an input range is changed.

Constant Value: "android.app.slice.extra.RANGE_VALUE"

EXTRA_SLIDER_VALUE

String EXTRA_SLIDER_VALUE

This constant was deprecated in API level P.
remove once support lib is update to use EXTRA_RANGE_VALUE instead

Key to retrieve an extra added to an intent when the value of a slider is changed.

Constant Value: "android.app.slice.extra.SLIDER_VALUE"

EXTRA_TOGGLE_STATE

String EXTRA_TOGGLE_STATE

Key to retrieve an extra added to an intent when a control is changed.

Constant Value: "android.app.slice.extra.TOGGLE_STATE"

HINT_ACTIONS

String HINT_ACTIONS

Hint that this slice contains a number of actions that can be grouped together in a sort of controls area of the UI.

Constant Value: "actions"

HINT_ERROR

String HINT_ERROR

A hint to indicate that this slice represents an error.

Constant Value: "error"

HINT_HORIZONTAL

String HINT_HORIZONTAL

Hint that list items within this slice or subslice would appear better if organized horizontally.

Constant Value: "horizontal"

HINT_KEYWORDS

String HINT_KEYWORDS

A hint to indicate that the contents of this subslice represent a list of keywords related to the parent slice. Expected to be on an item of format FORMAT_SLICE.

Constant Value: "keywords"

HINT_LARGE

String HINT_LARGE

Hint that this content is important and should be larger when displayed if possible.

Constant Value: "large"

HINT_LAST_UPDATED

String HINT_LAST_UPDATED

Hint indicating an item representing when the content was created or last updated.

Constant Value: "last_updated"

HINT_LIST

String HINT_LIST

Hint that all sub-items/sub-slices within this content should be considered to have HINT_LIST_ITEM.

Constant Value: "list"

HINT_LIST_ITEM

String HINT_LIST_ITEM

Hint that this item is part of a list and should be formatted as if is part of a list.

Constant Value: "list_item"

HINT_NO_TINT

String HINT_NO_TINT

Hint to indicate that this content should not be tinted.

Constant Value: "no_tint"

HINT_PARTIAL

String HINT_PARTIAL

Hint to indicate that this slice is incomplete and an update will be sent once loading is complete. Slices which contain HINT_PARTIAL will not be cached by the OS and should not be cached by apps.

Constant Value: "partial"

HINT_PERMISSION_REQUEST

String HINT_PERMISSION_REQUEST

A hint to indicate that this slice represents a permission request for showing slices.

Constant Value: "permission_request"

HINT_SEE_MORE

String HINT_SEE_MORE

A hint representing that this item should be used to indicate that there's more content associated with this slice.

Constant Value: "see_more"

HINT_SELECTED

String HINT_SELECTED

Hint indicating that this item (and its sub-items) are the current selection.

Constant Value: "selected"

HINT_SHORTCUT

String HINT_SHORTCUT

Hint to indicate that this content should only be displayed if the slice is presented as a shortcut.

Constant Value: "shortcut"

HINT_SUMMARY

String HINT_SUMMARY

Hint indicating this content should be shown instead of the normal content when the slice is in small format.

Constant Value: "summary"

HINT_TITLE

String HINT_TITLE

Hint that this content is a title of other content in the slice. This can also indicate that the content should be used in the shortcut representation of the slice (icon, label, action), normally this should be indicated by adding the hint on the action containing that content.

See also:

Constant Value: "title"

HINT_TTL

String HINT_TTL

Hint indicating an item representing a time-to-live for the content.

Constant Value: "ttl"

SUBTYPE_COLOR

String SUBTYPE_COLOR

Subtype to tag an item as representing a color. Expected to be on an item of format FORMAT_INT.

Constant Value: "color"

SUBTYPE_CONTENT_DESCRIPTION

String SUBTYPE_CONTENT_DESCRIPTION

Subtype to tag an item to use as a content description. Expected to be on an item of format FORMAT_TEXT.

Constant Value: "content_description"

SUBTYPE_LAYOUT_DIRECTION

String SUBTYPE_LAYOUT_DIRECTION

Subtype to indicate that this item indicates the layout direction for content in the slice. Expected to be an item of format FORMAT_INT.

Constant Value: "layout_direction"

SUBTYPE_MAX

String SUBTYPE_MAX

Subtype to tag an item as representing the max int value for a SUBTYPE_RANGE. Expected to be on an item of format FORMAT_INT.

Constant Value: "max"

SUBTYPE_MESSAGE

String SUBTYPE_MESSAGE

Subtype to indicate that this is a message as part of a communication sequence in this slice. Expected to be on an item of format FORMAT_SLICE.

Constant Value: "message"

SUBTYPE_MILLIS

String SUBTYPE_MILLIS

Subtype to tag an item as representing a time in milliseconds since midnight, January 1, 1970 UTC.

Constant Value: "millis"

SUBTYPE_PRIORITY

String SUBTYPE_PRIORITY

Subtype to tag an item representing priority. Expected to be on an item of format FORMAT_INT.

Constant Value: "priority"

SUBTYPE_RANGE

String SUBTYPE_RANGE

Subtype to tag an item as representing a range. Expected to be on an item of format FORMAT_SLICE containing a SUBTYPE_VALUE and possibly a SUBTYPE_MAX.

Constant Value: "range"

SUBTYPE_SLIDER

String SUBTYPE_SLIDER

This constant was deprecated in API level P.
remove once support lib is update to use SUBTYPE_RANGE instead

Subtype to tag an item as representing a slider.

Constant Value: "slider"

SUBTYPE_SOURCE

String SUBTYPE_SOURCE

Subtype to tag the source (i.e. sender) of a SUBTYPE_MESSAGE. Expected to be on an item of format FORMAT_TEXT, FORMAT_IMAGE or an FORMAT_SLICE containing them.

Constant Value: "source"

SUBTYPE_TOGGLE

String SUBTYPE_TOGGLE

Subtype to indicate that this content has a toggle action associated with it. To indicate that the toggle is on, use HINT_SELECTED. When the toggle state changes, the intent associated with it will be sent along with an extra EXTRA_TOGGLE_STATE which can be retrieved to see the new state of the toggle.

Constant Value: "toggle"

SUBTYPE_VALUE

String SUBTYPE_VALUE

Subtype to tag an item as representing the current int value for a SUBTYPE_RANGE. Expected to be on an item of format FORMAT_INT.

Constant Value: "value"

Fields

Protected constructors

Slice

Slice (Parcel in)

Parameters
in Parcel

Public methods

describeContents

int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

getItems

List<SliceItem> getItems ()

Returns
List<SliceItem> All child SliceItems that this Slice contains.

getSpec

SliceSpec getSpec ()

Returns
SliceSpec The spec for this slice

This value may be null.

getUri

Uri getUri ()

Returns
Uri The Uri that this Slice represents.

isCallerNeeded

boolean isCallerNeeded ()

Returns whether the caller for this slice matters.

Returns
boolean

writeToParcel

void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written.

flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.