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


open class SliceUtils
   ↳ androidx.slice.SliceUtils

Utilities for dealing with slices.


Nested classes


Holds options for how to handle SliceItems that cannot be serialized.


A listener used to receive events on slices parsed with parseSlice(Context, InputStream, String, SliceActionListener).


Exception thrown during parseSlice(Context, InputStream, String, SliceActionListener).

Public methods

open static Slice
parseSlice(@NonNull context: Context, @NonNull input: InputStream, @NonNull encoding: String, @NonNull listener: SliceUtils.SliceActionListener)

Parse a slice that has been previously serialized.

open static Unit
serializeSlice(@NonNull s: Slice, @NonNull context: Context, @NonNull output: OutputStream, @NonNull options: SliceUtils.SerializeOptions)

Serialize a slice to an OutputStream.

open static Slice
stripSlice(@NonNull s: Slice, mode: Int, isScrollable: Boolean)

Attempt to remove any extra content from the slice.

Public methods


@NonNull open static fun parseSlice(@NonNull context: Context, @NonNull input: InputStream, @NonNull encoding: String, @NonNull listener: SliceUtils.SliceActionListener): Slice

Parse a slice that has been previously serialized.

Parses a slice that was serialized with serializeSlice.

Note: Slices returned by this cannot be passed to SliceConvert#unwrap(Slice).

input Context: The input stream to read from.
encoding Context: The encoding to read as.
listener Context: Listener used to handle actions when reconstructing the slice.
SliceParseException if the InputStream cannot be parsed.


open static fun serializeSlice(@NonNull s: Slice, @NonNull context: Context, @NonNull output: OutputStream, @NonNull options: SliceUtils.SerializeOptions): Unit

Serialize a slice to an OutputStream.

The serialized slice can later be read into slice form again with parseSlice. Some slice types cannot be serialized, their handling is controlled by SerializeOptions.

s Slice: The slice to serialize.
context Slice: Context used to load any resources in the slice.
output Slice: The output of the serialization.
options Slice: Options defining how to handle non-serializable items.
IllegalArgumentException if the slice cannot be serialized using the given options.


@NonNull open static fun stripSlice(@NonNull s: Slice, mode: Int, isScrollable: Boolean): Slice

Attempt to remove any extra content from the slice.

This is meant to be used alongside serializeSlice to reduce the size of a slice by only including data for the slice to be displayed in a specific mode.

s Slice: The slice to strip.
mode Slice: The mode that will be used with SliceView#setMode to display the slice.
isScrollable Slice: The value that will be used with SliceView#setScrollable to display the slice.
Slice: returns A new smaller slice if stripping can be done, or the original slice if no content can be removed.