lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

Slice.Builder

public static class Slice.Builder
extends Object

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


A Builder used to construct Slices

Summary

Public constructors

Slice.Builder(Uri uri, SliceSpec spec)

Create a builder which will construct a Slice for the given Uri.

Slice.Builder(Slice.Builder parent)

Create a builder for a Slice that is a sub-slice of the slice being constructed by the provided builder.

Public methods

Slice.Builder addAction(PendingIntent action, Slice s, String subType)

Add an action to the slice being constructed

Slice.Builder addBundle(Bundle bundle, String subType, List<String> hints)

Add a bundle to the slice being constructed.

Slice.Builder addHints(List<String> hints)

Add hints to the Slice being constructed

Slice.Builder addIcon(Icon icon, String subType, List<String> hints)

Add an image to the slice being constructed

Slice.Builder addInt(int value, String subType, List<String> hints)

Add an integer to the slice being constructed

Slice.Builder addLong(long value, String subType, List<String> hints)

Add a long to the slice being constructed

Slice.Builder addRemoteInput(RemoteInput remoteInput, String subType, List<String> hints)

Add remote input to the slice being constructed

Slice.Builder addSubSlice(Slice slice, String subType)

Add a sub-slice to the slice being constructed

Slice.Builder addText(CharSequence text, String subType, List<String> hints)

Add text to the slice being constructed

Slice build()

Construct the slice.

Slice.Builder setCallerNeeded(boolean callerNeeded)

Tells the system whether for this slice the return value of SliceProvider.onBindSlice(Uri, java.util.Set) may be different depending on ContentProvider.getCallingPackage() and should not be cached for multiple apps.

Inherited methods

Public constructors

Slice.Builder

added in API level 28
public Slice.Builder (Uri uri, 
                SliceSpec spec)

Create a builder which will construct a Slice for the given Uri.

Parameters
uri Uri: Uri to tag for this slice.

This value must never be null.

spec SliceSpec: the spec for this slice.

Slice.Builder

added in API level 28
public Slice.Builder (Slice.Builder parent)

Create a builder for a Slice that is a sub-slice of the slice being constructed by the provided builder.

Parameters
parent Slice.Builder: The builder constructing the parent slice

This value must never be null.

Public methods

addAction

added in API level 28
public Slice.Builder addAction (PendingIntent action, 
                Slice s, 
                String subType)

Add an action to the slice being constructed

Parameters
action PendingIntent

This value must never be null.

s Slice

This value must never be null.

subType String: Optional template-specific type information

This value may be null.

Value is SUBTYPE_COLOR, SUBTYPE_CONTENT_DESCRIPTION, SUBTYPE_MAX, SUBTYPE_MESSAGE, SUBTYPE_PRIORITY, SUBTYPE_RANGE, SUBTYPE_SOURCE, SUBTYPE_TOGGLE, SUBTYPE_VALUE or SUBTYPE_LAYOUT_DIRECTION.

Returns
Slice.Builder

addBundle

added in API level 28
public Slice.Builder addBundle (Bundle bundle, 
                String subType, 
                List<String> hints)

Add a bundle to the slice being constructed.

Expected to be used for support library extension, should not be used for general development

Parameters
bundle Bundle

subType String: Optional template-specific type information

This value may be null.

Value is SUBTYPE_COLOR, SUBTYPE_CONTENT_DESCRIPTION, SUBTYPE_MAX, SUBTYPE_MESSAGE, SUBTYPE_PRIORITY, SUBTYPE_RANGE, SUBTYPE_SOURCE, SUBTYPE_TOGGLE, SUBTYPE_VALUE or SUBTYPE_LAYOUT_DIRECTION.

hints List

Value is HINT_TITLE, HINT_LIST, HINT_LIST_ITEM, HINT_LARGE, HINT_ACTIONS, HINT_SELECTED, HINT_NO_TINT, HINT_SHORTCUT, HINT_HORIZONTAL, HINT_PARTIAL, HINT_SEE_MORE, HINT_KEYWORDS, HINT_ERROR, HINT_TTL, HINT_LAST_UPDATED or HINT_PERMISSION_REQUEST.

Returns
Slice.Builder

addRemoteInput

added in API level 28
public Slice.Builder addRemoteInput (RemoteInput remoteInput, 
                String subType, 
                List<String> hints)

Add remote input to the slice being constructed

Parameters
remoteInput RemoteInput

subType String: Optional template-specific type information

This value may be null.

Value is SUBTYPE_COLOR, SUBTYPE_CONTENT_DESCRIPTION, SUBTYPE_MAX, SUBTYPE_MESSAGE, SUBTYPE_PRIORITY, SUBTYPE_RANGE, SUBTYPE_SOURCE, SUBTYPE_TOGGLE, SUBTYPE_VALUE or SUBTYPE_LAYOUT_DIRECTION.

hints List

Value is HINT_TITLE, HINT_LIST, HINT_LIST_ITEM, HINT_LARGE, HINT_ACTIONS, HINT_SELECTED, HINT_NO_TINT, HINT_SHORTCUT, HINT_HORIZONTAL, HINT_PARTIAL, HINT_SEE_MORE, HINT_KEYWORDS, HINT_ERROR, HINT_TTL, HINT_LAST_UPDATED or HINT_PERMISSION_REQUEST.

Returns
Slice.Builder

addSubSlice

added in API level 28
public Slice.Builder addSubSlice (Slice slice, 
                String subType)

Add a sub-slice to the slice being constructed

Parameters
slice Slice

This value must never be null.

subType String: Optional template-specific type information

This value may be null.

Value is SUBTYPE_COLOR, SUBTYPE_CONTENT_DESCRIPTION, SUBTYPE_MAX, SUBTYPE_MESSAGE, SUBTYPE_PRIORITY, SUBTYPE_RANGE, SUBTYPE_SOURCE, SUBTYPE_TOGGLE, SUBTYPE_VALUE or SUBTYPE_LAYOUT_DIRECTION.

Returns
Slice.Builder

addText

added in API level 28
public Slice.Builder addText (CharSequence text, 
                String subType, 
                List<String> hints)

Add text to the slice being constructed

Parameters
text CharSequence

subType String: Optional template-specific type information

This value may be null.

Value is SUBTYPE_COLOR, SUBTYPE_CONTENT_DESCRIPTION, SUBTYPE_MAX, SUBTYPE_MESSAGE, SUBTYPE_PRIORITY, SUBTYPE_RANGE, SUBTYPE_SOURCE, SUBTYPE_TOGGLE, SUBTYPE_VALUE or SUBTYPE_LAYOUT_DIRECTION.

hints List

Value is HINT_TITLE, HINT_LIST, HINT_LIST_ITEM, HINT_LARGE, HINT_ACTIONS, HINT_SELECTED, HINT_NO_TINT, HINT_SHORTCUT, HINT_HORIZONTAL, HINT_PARTIAL, HINT_SEE_MORE, HINT_KEYWORDS, HINT_ERROR, HINT_TTL, HINT_LAST_UPDATED or HINT_PERMISSION_REQUEST.

Returns
Slice.Builder

build

added in API level 28
public Slice build ()

Construct the slice.

Returns
Slice

setCallerNeeded

added in API level 28
public Slice.Builder setCallerNeeded (boolean callerNeeded)

Tells the system whether for this slice the return value of SliceProvider.onBindSlice(Uri, java.util.Set) may be different depending on ContentProvider.getCallingPackage() and should not be cached for multiple apps.

Parameters
callerNeeded boolean

Returns
Slice.Builder