SliceItem

public final class SliceItem
extends Object implements VersionedParcelable

java.lang.Object
   ↳ androidx.slice.SliceItem


A SliceItem is a single unit in the tree structure of a Slice.

A SliceItem a piece of content and some hints about what that content means or how it should be displayed. The types of content can be:

The hints that a SliceItem are a set of strings which annotate the content. The hints that are guaranteed to be understood by the system are defined on Slice.

Summary

Public methods

static ParcelableSpan createSensitiveSpan()

Creates a span object that identifies content that should be redacted when acquired using getRedactedText().

void fireAction(Context context, Intent i)

Trigger the action on this SliceItem.

PendingIntent getAction()
String getFormat()

Get the format of this SliceItem.

List<String> getHints()

Gets all hints associated with this SliceItem.

IconCompat getIcon()
int getInt()
long getLong()
CharSequence getRedactedText()

Get the same content as getText() except with content that should be excluded from persistent logs because it was tagged with createSensitiveSpan().

Slice getSlice()
String getSubType()

Get the sub-type of this SliceItem.

CharSequence getText()
boolean hasHint(String hint)
void onPostParceling()

Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.

void onPreParceling(boolean isStream)

Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.

String toString()

Inherited methods

Public methods

createSensitiveSpan

public static ParcelableSpan createSensitiveSpan ()

Creates a span object that identifies content that should be redacted when acquired using getRedactedText().

Returns
ParcelableSpan

fireAction

public void fireAction (Context context, 
                Intent i)

Trigger the action on this SliceItem.

Parameters
context Context: The Context to use when sending the PendingIntent.

i Intent: The intent to use when sending the PendingIntent.

Throws
PendingIntent.CanceledException

getAction

public PendingIntent getAction ()

Returns
PendingIntent The pending intent held by this SliceItem.FORMAT_ACTION SliceItem

getFormat

public String getFormat ()

Get the format of this SliceItem.

The format will be one of the following types supported by the platform:

Returns
String

See also:

getHints

public List<String> getHints ()

Gets all hints associated with this SliceItem.

Returns
List<String> Array of hints.

getIcon

public IconCompat getIcon ()

Returns
IconCompat The icon held by this SliceItem.FORMAT_IMAGE SliceItem

getInt

public int getInt ()

Returns
int The color held by this SliceItem.FORMAT_INT SliceItem

getLong

public long getLong ()

Returns
long The long held by this SliceItem.FORMAT_LONG SliceItem

getRedactedText

public CharSequence getRedactedText ()

Get the same content as getText() except with content that should be excluded from persistent logs because it was tagged with createSensitiveSpan().

Returns
CharSequence The text held by this SliceItem.FORMAT_TEXT SliceItem

getSlice

public Slice getSlice ()

Returns
Slice The slice held by this SliceItem.FORMAT_ACTION or SliceItem.FORMAT_SLICE SliceItem

getSubType

public String getSubType ()

Get the sub-type of this SliceItem.

Subtypes provide additional information about the type of this information beyond basic interpretations inferred by getFormat(). For example a slice may contain many SliceItem.FORMAT_TEXT items, but only some of them may be Slice.SUBTYPE_MESSAGE.

Returns
String

See also:

getText

public CharSequence getText ()

Returns
CharSequence The text held by this SliceItem.FORMAT_TEXT SliceItem

hasHint

public boolean hasHint (String hint)

Parameters
hint String: The hint to check for

Returns
boolean true if this item contains the given hint

onPostParceling

public void onPostParceling ()

Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.

onPreParceling

public void onPreParceling (boolean isStream)

Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.

Parameters
isStream boolean

toString

public String toString ()

Returns
String A string representation of this slice item.