The second Android 11 Developer Preview is now available, test it out and share your feedback.

SliceAction

open class SliceAction : SliceAction
kotlin.Any
   ↳ androidx.slice.builders.SliceAction

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

Summary

Public methods

open static SliceAction!
create(@NonNull action: PendingIntent, @NonNull actionIcon: IconCompat, imageMode: Int, @NonNull actionTitle: CharSequence)

Construct a SliceAction representing a tappable icon.

open static SliceAction!
create(@NonNull action: RemoteCallback, @NonNull actionIcon: IconCompat, imageMode: Int, @NonNull actionTitle: CharSequence)

Construct a SliceAction representing a tappable icon.

open static SliceAction!
createDeeplink(@NonNull action: PendingIntent, @NonNull actionIcon: IconCompat, imageMode: Int, @NonNull actionTitle: CharSequence)

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

open static SliceAction!
createDeeplink(@NonNull action: RemoteCallback, @NonNull actionIcon: IconCompat, imageMode: Int, @NonNull actionTitle: CharSequence)

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

open static SliceAction!
createToggle(@NonNull action: PendingIntent, @NonNull actionTitle: CharSequence, isChecked: Boolean)

Construct a SliceAction representing a default toggle.

open static SliceAction!
createToggle(@NonNull action: RemoteCallback, @NonNull actionTitle: CharSequence, isChecked: Boolean)

Construct a SliceAction representing a default toggle.

open static SliceAction!
createToggle(@NonNull action: PendingIntent, @NonNull actionIcon: IconCompat, @NonNull actionTitle: CharSequence, isChecked: Boolean)

Construct a SliceAction representing a custom toggle icon.

open static SliceAction!
createToggle(@NonNull action: RemoteCallback, @NonNull actionIcon: IconCompat, @NonNull actionTitle: CharSequence, isChecked: Boolean)

Construct a SliceAction representing a custom toggle icon.

open PendingIntent

open CharSequence?

open IconCompat?

open Int

open Int

open CharSequence

open Boolean

open Boolean

open Boolean

open Boolean

open SliceAction
setChecked(isChecked: Boolean)

open SliceAction
setContentDescription(@NonNull description: CharSequence)

open SliceAction
setPriority(priority: Int)

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

Public methods

create

open static fun create(
    @NonNull action: PendingIntent,
    @NonNull actionIcon: IconCompat,
    imageMode: Int,
    @NonNull actionTitle: CharSequence
): SliceAction!

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).

create

open static fun create(
    @NonNull action: RemoteCallback,
    @NonNull actionIcon: IconCompat,
    imageMode: Int,
    @NonNull actionTitle: CharSequence
): SliceAction!

Construct a SliceAction representing a tappable icon.

Parameters
action RemoteCallback: the remote callback 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).

createDeeplink

open static fun createDeeplink(
    @NonNull action: PendingIntent,
    @NonNull actionIcon: IconCompat,
    imageMode: Int,
    @NonNull actionTitle: CharSequence
): SliceAction!

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).

createDeeplink

open static fun createDeeplink(
    @NonNull action: RemoteCallback,
    @NonNull actionIcon: IconCompat,
    imageMode: Int,
    @NonNull actionTitle: CharSequence
): SliceAction!

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

Parameters
action RemoteCallback: the remote callback 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).

createToggle

open static fun createToggle(
    @NonNull action: PendingIntent,
    @NonNull actionTitle: CharSequence,
    isChecked: Boolean
): SliceAction!

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.

createToggle

open static fun createToggle(
    @NonNull action: RemoteCallback,
    @NonNull actionTitle: CharSequence,
    isChecked: Boolean
): SliceAction!

Construct a SliceAction representing a default toggle.

Parameters
action RemoteCallback: the remote callback 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.

createToggle

open static fun createToggle(
    @NonNull action: PendingIntent,
    @NonNull actionIcon: IconCompat,
    @NonNull actionTitle: CharSequence,
    isChecked: Boolean
): SliceAction!

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.

createToggle

open static fun createToggle(
    @NonNull action: RemoteCallback,
    @NonNull actionIcon: IconCompat,
    @NonNull actionTitle: CharSequence,
    isChecked: Boolean
): SliceAction!

Construct a SliceAction representing a custom toggle icon.

Parameters
action RemoteCallback: the remote callback 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.

getAction

@NonNull open fun getAction(): PendingIntent
Return
PendingIntent the PendingIntent associated with this action.

getContentDescription

@Nullable open fun getContentDescription(): CharSequence?
Return
CharSequence? the content description to use for this action.

getIcon

@Nullable open fun getIcon(): IconCompat?
Return
IconCompat? the Icon to display for this action. This can be null when the action represented is a default toggle.

getImageMode

open fun getImageMode(): Int
Return
Int the image mode to use for this action.

getPriority

open fun getPriority(): Int
Return
Int the priority associated with this action, -1 if unset.

getTitle

@NonNull open fun getTitle(): CharSequence
Return
CharSequence the title for this action.

isActivity

open fun isActivity(): Boolean

isChecked

open fun isChecked(): Boolean
Return
Boolean whether the state of this action is checked or not; only used for toggle actions.

isDefaultToggle

open fun isDefaultToggle(): Boolean
Return
Boolean whether this action is a toggle using the standard switch control.

isToggle

open fun isToggle(): Boolean
Return
Boolean whether this action represents a toggle (i.e. has a checked and unchecked state).

setChecked

@NonNull open fun setChecked(isChecked: Boolean): SliceAction
Parameters
isChecked Boolean: whether the state of this action is checked or not; only used for toggle actions.

setContentDescription

@NonNull open fun setContentDescription(@NonNull description: CharSequence): SliceAction
Parameters
description CharSequence: the content description for this action.

setPriority

@NonNull open fun setPriority(priority: Int): SliceAction

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