Added in API level 28
Deprecated in API level 35

Slice.Builder


public static class Slice.Builder
extends Object

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


This class was deprecated in API level 35.
Slice framework has been deprecated, it will not receive any updates from ERROR(/android.os.Build.VANILLA_ICE_CREAM) and forward. If you are looking for a framework that sends displayable data from one app to another, consider using AppSearchManager.

A Builder used to construct Slices

Summary

Public constructors

Builder(Uri uri, SliceSpec spec)

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

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 SliceProvider#getCallingPackage() and should not be cached for multiple apps.

Inherited methods

Public constructors

Builder

Added in API level 28
public 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 cannot be null.

spec SliceSpec: the spec for this slice.

Builder

Added in API level 28
public 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 cannot 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 cannot be null.

s Slice: This value cannot be null.

subType String: Optional template-specific type information This value may be null. Value is Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.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 Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.SUBTYPE_LAYOUT_DIRECTION

hints List: Value is Slice.HINT_TITLE, Slice.HINT_LIST, Slice.HINT_LIST_ITEM, Slice.HINT_LARGE, Slice.HINT_ACTIONS, Slice.HINT_SELECTED, Slice.HINT_NO_TINT, Slice.HINT_SHORTCUT, android.app.slice.Slice.HINT_TOGGLE, Slice.HINT_HORIZONTAL, Slice.HINT_PARTIAL, Slice.HINT_SEE_MORE, Slice.HINT_KEYWORDS, Slice.HINT_ERROR, Slice.HINT_TTL, Slice.HINT_LAST_UPDATED, or Slice.HINT_PERMISSION_REQUEST

Returns
Slice.Builder

addIcon

Added in API level 28
public Slice.Builder addIcon (Icon icon, 
                String subType, 
                List<String> hints)

Add an image to the slice being constructed

Parameters
icon Icon

subType String: Optional template-specific type information This value may be null. Value is Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.SUBTYPE_LAYOUT_DIRECTION

hints List: Value is Slice.HINT_TITLE, Slice.HINT_LIST, Slice.HINT_LIST_ITEM, Slice.HINT_LARGE, Slice.HINT_ACTIONS, Slice.HINT_SELECTED, Slice.HINT_NO_TINT, Slice.HINT_SHORTCUT, android.app.slice.Slice.HINT_TOGGLE, Slice.HINT_HORIZONTAL, Slice.HINT_PARTIAL, Slice.HINT_SEE_MORE, Slice.HINT_KEYWORDS, Slice.HINT_ERROR, Slice.HINT_TTL, Slice.HINT_LAST_UPDATED, or Slice.HINT_PERMISSION_REQUEST

Returns
Slice.Builder

addInt

Added in API level 28
public Slice.Builder addInt (int value, 
                String subType, 
                List<String> hints)

Add an integer to the slice being constructed

Parameters
value int

subType String: Optional template-specific type information This value may be null. Value is Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.SUBTYPE_LAYOUT_DIRECTION

hints List: Value is Slice.HINT_TITLE, Slice.HINT_LIST, Slice.HINT_LIST_ITEM, Slice.HINT_LARGE, Slice.HINT_ACTIONS, Slice.HINT_SELECTED, Slice.HINT_NO_TINT, Slice.HINT_SHORTCUT, android.app.slice.Slice.HINT_TOGGLE, Slice.HINT_HORIZONTAL, Slice.HINT_PARTIAL, Slice.HINT_SEE_MORE, Slice.HINT_KEYWORDS, Slice.HINT_ERROR, Slice.HINT_TTL, Slice.HINT_LAST_UPDATED, or Slice.HINT_PERMISSION_REQUEST

Returns
Slice.Builder

addLong

Added in API level 28
public Slice.Builder addLong (long value, 
                String subType, 
                List<String> hints)

Add a long to the slice being constructed

Parameters
value long

subType String: Optional template-specific type information This value may be null. Value is Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.SUBTYPE_LAYOUT_DIRECTION

hints List: Value is Slice.HINT_TITLE, Slice.HINT_LIST, Slice.HINT_LIST_ITEM, Slice.HINT_LARGE, Slice.HINT_ACTIONS, Slice.HINT_SELECTED, Slice.HINT_NO_TINT, Slice.HINT_SHORTCUT, android.app.slice.Slice.HINT_TOGGLE, Slice.HINT_HORIZONTAL, Slice.HINT_PARTIAL, Slice.HINT_SEE_MORE, Slice.HINT_KEYWORDS, Slice.HINT_ERROR, Slice.HINT_TTL, Slice.HINT_LAST_UPDATED, or Slice.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 Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.SUBTYPE_LAYOUT_DIRECTION

hints List: Value is Slice.HINT_TITLE, Slice.HINT_LIST, Slice.HINT_LIST_ITEM, Slice.HINT_LARGE, Slice.HINT_ACTIONS, Slice.HINT_SELECTED, Slice.HINT_NO_TINT, Slice.HINT_SHORTCUT, android.app.slice.Slice.HINT_TOGGLE, Slice.HINT_HORIZONTAL, Slice.HINT_PARTIAL, Slice.HINT_SEE_MORE, Slice.HINT_KEYWORDS, Slice.HINT_ERROR, Slice.HINT_TTL, Slice.HINT_LAST_UPDATED, or Slice.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 cannot be null.

subType String: Optional template-specific type information This value may be null. Value is Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.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 Slice.SUBTYPE_COLOR, Slice.SUBTYPE_CONTENT_DESCRIPTION, Slice.SUBTYPE_MAX, Slice.SUBTYPE_MESSAGE, Slice.SUBTYPE_PRIORITY, Slice.SUBTYPE_RANGE, Slice.SUBTYPE_SOURCE, Slice.SUBTYPE_TOGGLE, Slice.SUBTYPE_VALUE, or Slice.SUBTYPE_LAYOUT_DIRECTION

hints List: Value is Slice.HINT_TITLE, Slice.HINT_LIST, Slice.HINT_LIST_ITEM, Slice.HINT_LARGE, Slice.HINT_ACTIONS, Slice.HINT_SELECTED, Slice.HINT_NO_TINT, Slice.HINT_SHORTCUT, android.app.slice.Slice.HINT_TOGGLE, Slice.HINT_HORIZONTAL, Slice.HINT_PARTIAL, Slice.HINT_SEE_MORE, Slice.HINT_KEYWORDS, Slice.HINT_ERROR, Slice.HINT_TTL, Slice.HINT_LAST_UPDATED, or Slice.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 SliceProvider#getCallingPackage() and should not be cached for multiple apps.

Parameters
callerNeeded boolean

Returns
Slice.Builder