SliceAction

public class SliceAction
extends Object implements SliceAction

java.lang.Object
   ↳ androidx.slice.builders.SliceAction


Class representing an action, supports tappable icons, custom toggle icons, and default toggles.

Summary

Public methods

static SliceAction create(PendingIntent action, IconCompat actionIcon, int imageMode, CharSequence actionTitle)

Construct a SliceAction representing a tappable icon.

static SliceAction createDeeplink(PendingIntent action, IconCompat actionIcon, int imageMode, CharSequence actionTitle)

Construct a SliceAction representing a tappable icon that launches an activity when clicked.

static SliceAction createToggle(PendingIntent action, IconCompat actionIcon, CharSequence actionTitle, boolean isChecked)

Construct a SliceAction representing a custom toggle icon.

static SliceAction createToggle(PendingIntent action, CharSequence actionTitle, boolean isChecked)

Construct a SliceAction representing a default toggle.

PendingIntent getAction()
CharSequence getContentDescription()
IconCompat getIcon()
int getImageMode()
int getPriority()
CharSequence getTitle()
boolean isActivity()
boolean isChecked()
boolean isDefaultToggle()
boolean isToggle()
SliceAction setChecked(boolean isChecked)
SliceAction setContentDescription(CharSequence description)
SliceAction setPriority(int priority)

Sets the priority of this action, with the lowest priority having the highest ranking.

Inherited methods

Public methods

create

public static SliceAction create (PendingIntent action, 
                IconCompat actionIcon, 
                int imageMode, 
                CharSequence actionTitle)

Construct a SliceAction representing a tappable icon.

Parameters
action PendingIntent: the pending intent to invoke for this action.

actionIcon IconCompat: the icon to display for this action.

imageMode int: the mode this icon should be displayed in.

actionTitle CharSequence: the title for this action, also used for content description if one hasn't been set via setContentDescription(CharSequence).

Returns
SliceAction

createDeeplink

public static SliceAction createDeeplink (PendingIntent action, 
                IconCompat actionIcon, 
                int imageMode, 
                CharSequence actionTitle)

Construct a SliceAction representing a tappable icon that launches an activity when clicked.

Parameters
action PendingIntent: the pending intent to invoke for this action.

actionIcon IconCompat: the icon to display for this action.

imageMode int: the mode this icon should be displayed in.

actionTitle CharSequence: the title for this action, also used for content description if one hasn't been set via setContentDescription(CharSequence).

Returns
SliceAction

createToggle

public static SliceAction createToggle (PendingIntent action, 
                IconCompat actionIcon, 
                CharSequence actionTitle, 
                boolean isChecked)

Construct a SliceAction representing a custom toggle icon.

Parameters
action PendingIntent: the pending intent to invoke for this toggle.

actionIcon IconCompat: the icon to display for this toggle, should have a checked and unchecked state.

actionTitle CharSequence: the title for this toggle, also used for content description if one hasn't been set via setContentDescription(CharSequence).

isChecked boolean: the state of the toggle.

Returns
SliceAction

createToggle

public static SliceAction createToggle (PendingIntent action, 
                CharSequence actionTitle, 
                boolean isChecked)

Construct a SliceAction representing a default toggle.

Parameters
action PendingIntent: the pending intent to invoke for this toggle.

actionTitle CharSequence: the title for this toggle, also used for content description if one hasn't been set via setContentDescription(CharSequence).

isChecked boolean: the state of the toggle.

Returns
SliceAction

getAction

public PendingIntent getAction ()

Returns
PendingIntent the PendingIntent associated with this action.

getContentDescription

public CharSequence getContentDescription ()

Returns
CharSequence the content description to use for this action.

getIcon

public IconCompat getIcon ()

Returns
IconCompat the Icon to display for this action. This can be null when the action represented is a default toggle.

getImageMode

public int getImageMode ()

Returns
int the image mode to use for this action.

getPriority

public int getPriority ()

Returns
int the priority associated with this action, -1 if unset.

getTitle

public CharSequence getTitle ()

Returns
CharSequence the title for this action.

isActivity

public boolean isActivity ()

Returns
boolean

isChecked

public boolean isChecked ()

Returns
boolean whether the state of this action is checked or not; only used for toggle actions.

isDefaultToggle

public boolean isDefaultToggle ()

Returns
boolean whether this action is a toggle using the standard switch control.

isToggle

public boolean isToggle ()

Returns
boolean whether this action represents a toggle (i.e. has a checked and unchecked state).

setChecked

public SliceAction setChecked (boolean isChecked)

Parameters
isChecked boolean: whether the state of this action is checked or not; only used for toggle actions.

Returns
SliceAction

setContentDescription

public SliceAction setContentDescription (CharSequence description)

Parameters
description CharSequence: the content description for this action.

Returns
SliceAction

setPriority

public SliceAction setPriority (int priority)

Sets the priority of this action, with the lowest priority having the highest ranking.

Parameters
priority int

Returns
SliceAction