ShortcutInfoCompat.Builder

Added in 1.1.0

class ShortcutInfoCompat.Builder


Builder class for ShortcutInfoCompat objects.

Summary

Public constructors

Builder(context: Context, id: String)

Public functions

ShortcutInfoCompat.Builder

Associates a shortcut with a capability without any parameters.

ShortcutInfoCompat.Builder
addCapabilityBinding(
    capability: String,
    parameter: String,
    parameterValues: (Mutable)List<String!>
)

Associates a shortcut with a capability, and a parameter of that capability.

ShortcutInfoCompat

Creates a ShortcutInfoCompat instance.

ShortcutInfoCompat.Builder

Sets the target activity.

ShortcutInfoCompat.Builder

Badges the icon before passing it over to the Launcher.

ShortcutInfoCompat.Builder
setCategories(categories: (Mutable)Set<String!>)

Sets categories for a shortcut.

ShortcutInfoCompat.Builder
setDisabledMessage(disabledMessage: CharSequence)

Sets the message that should be shown when the user attempts to start a shortcut that is disabled.

ShortcutInfoCompat.Builder

Sets which surfaces a shortcut will be excluded from.

ShortcutInfoCompat.Builder

Extras that the app can set for any purpose.

ShortcutInfoCompat.Builder

Sets an icon of a shortcut.

ShortcutInfoCompat.Builder
setIntent(intent: Intent)

Sets the intent of a shortcut.

ShortcutInfoCompat.Builder
setIntents(intents: Array<Intent!>)

Sets multiple intents instead of a single intent, in order to launch an activity with other activities in back stack.

ShortcutInfoCompat.Builder

Sets the corresponding fields indicating this shortcut is aimed for conversation.

ShortcutInfoCompat.Builder

Sets the LocusIdCompat associated with this shortcut.

ShortcutInfoCompat.Builder

Sets the text of a shortcut.

ShortcutInfoCompat.Builder

This function is deprecated.

Use {@ink #setLongLived(boolean)) instead.

ShortcutInfoCompat.Builder
setLongLived(longLived: Boolean)

Sets if a shortcut would be valid even if it has been unpublished/invisible by the app (as a dynamic or pinned shortcut).

ShortcutInfoCompat.Builder
setPerson(person: Person)

Associate a person to a shortcut.

ShortcutInfoCompat.Builder
setPersons(persons: Array<Person!>)

Sets multiple persons instead of a single person.

ShortcutInfoCompat.Builder
setRank(rank: Int)

Sets rank of a shortcut, which is a non-negative value that's used by the system to sort shortcuts.

ShortcutInfoCompat.Builder

Sets the short title of a shortcut.

ShortcutInfoCompat.Builder
setSliceUri(sliceUri: Uri)

Sets the slice uri for a shortcut.

Public constructors

Builder

Added in 1.1.0
Builder(context: Context, id: String)

Public functions

addCapabilityBinding

Added in 1.6.0
fun addCapabilityBinding(capability: String): ShortcutInfoCompat.Builder

Associates a shortcut with a capability without any parameters. Used when the shortcut is an instance of a capability.

This method can be called multiple times to associate multiple capabilities with this shortcut.

Parameters
capability: String

capability associated with the shortcut. e.g. actions.intent .START_EXERCISE.

addCapabilityBinding

Added in 1.6.0
fun addCapabilityBinding(
    capability: String,
    parameter: String,
    parameterValues: (Mutable)List<String!>
): ShortcutInfoCompat.Builder

Associates a shortcut with a capability, and a parameter of that capability. Used when the shortcut is an instance of a capability.

This method can be called multiple times to associate multiple capabilities with this shortcut, or add multiple parameters to the same capability.

Parameters
capability: String

capability associated with the shortcut. e.g. actions.intent .START_EXERCISE.

parameter: String

the parameter associated with the capability. e.g. exercise.name.

parameterValues: (Mutable)List<String!>

a list of values for that parameters. The first value will be the primary name, while the rest will be alternative names. If the values are empty, then the parameter will not be saved in the shortcut.

build

Added in 1.1.0
fun build(): ShortcutInfoCompat

Creates a ShortcutInfoCompat instance.

setActivity

Added in 1.1.0
fun setActivity(activity: ComponentName): ShortcutInfoCompat.Builder

Sets the target activity. A shortcut will be shown along with this activity's icon on the launcher.

setAlwaysBadged

Added in 1.1.0
fun setAlwaysBadged(): ShortcutInfoCompat.Builder

Badges the icon before passing it over to the Launcher.

Launcher automatically badges ShortcutInfo, so only the legacy shortcut icon, Intent.ShortcutIconResource is badged. This field is ignored when using ShortcutInfo on API 25 and above.

If the shortcut is associated with an activity, the activity icon is used as the badge, otherwise application icon is used.

See also
setActivity

setCategories

Added in 1.1.0
fun setCategories(categories: (Mutable)Set<String!>): ShortcutInfoCompat.Builder

Sets categories for a shortcut.

  • Launcher apps may use this information to categorize shortcuts
  • Used by the system to associate a published Sharing Shortcut with supported mimeTypes. Required for published Sharing Shortcuts with a matching category declared in share targets, defined in the app's manifest linked shortcuts xml file.
See also
getCategories

setDisabledMessage

Added in 1.1.0
fun setDisabledMessage(disabledMessage: CharSequence): ShortcutInfoCompat.Builder

Sets the message that should be shown when the user attempts to start a shortcut that is disabled.

setExcludedFromSurfaces

Added in 1.8.0
fun setExcludedFromSurfaces(surfaces: Int): ShortcutInfoCompat.Builder

Sets which surfaces a shortcut will be excluded from. This API is reserved for future extension. Currently, marking a shortcut to be excluded from SURFACE_LAUNCHER will not publish the shortcut, thus the following operations will be a no-op: pushDynamicShortcut, addDynamicShortcuts, and setDynamicShortcuts.

On API <= 31, shortcuts that are excluded from SURFACE_LAUNCHER are not actually sent to ShortcutManager. These shortcuts might still be made available to other surfaces via alternative means.

setExtras

Added in 1.5.0
fun setExtras(extras: PersistableBundle): ShortcutInfoCompat.Builder

Extras that the app can set for any purpose.

Apps can store arbitrary shortcut metadata in extras and retrieve the metadata later using getExtras.

See also
getExtras

setIcon

Added in 1.1.0
fun setIcon(icon: IconCompat!): ShortcutInfoCompat.Builder

Sets an icon of a shortcut.

setIntent

Added in 1.1.0
fun setIntent(intent: Intent): ShortcutInfoCompat.Builder

Sets the intent of a shortcut. Alternatively, setIntents can be used to launch an activity with other activities in the back stack.

This is a mandatory field when publishing a new shortcut.

The given intent can contain extras, but these extras must contain values of primitive types in order for the system to persist these values.

setIntents

Added in 1.1.0
fun setIntents(intents: Array<Intent!>): ShortcutInfoCompat.Builder

Sets multiple intents instead of a single intent, in order to launch an activity with other activities in back stack. Use android.app.TaskStackBuilder to build intents. The last element in the list represents the only intent that doesn't place an activity on the back stack.

setIsConversation

Added in 1.5.0
fun setIsConversation(): ShortcutInfoCompat.Builder

Sets the corresponding fields indicating this shortcut is aimed for conversation.

If the shortcut is not associated with a LocusIdCompat, a LocusIdCompat based on getId will be added upon build

Additionally, the shortcut will be long-lived.

See also
setLongLived

setLocusId

Added in 1.5.0
fun setLocusId(locusId: LocusIdCompat?): ShortcutInfoCompat.Builder

Sets the LocusIdCompat associated with this shortcut.

This method should be called when the LocusIdCompat is used in other places (such as androidx.core.app.NotificationCompat and android.view.contentcapture.ContentCaptureContext) so the device's intelligence services can correlate them.

setLongLabel

Added in 1.1.0
fun setLongLabel(longLabel: CharSequence): ShortcutInfoCompat.Builder

Sets the text of a shortcut.

This field is intended to be more descriptive than the shortcut title. The launcher shows this instead of the short title when it has enough space.

The recommend maximum length is 25 characters.

setLongLived

Added in 1.1.0
Deprecated in 1.2.0
fun setLongLived(): ShortcutInfoCompat.Builder

setLongLived

Added in 1.2.0
fun setLongLived(longLived: Boolean): ShortcutInfoCompat.Builder

Sets if a shortcut would be valid even if it has been unpublished/invisible by the app (as a dynamic or pinned shortcut). If it is long lived, it can be cached by various system services even after it has been unpublished as a dynamic shortcut.

setPerson

Added in 1.1.0
fun setPerson(person: Person): ShortcutInfoCompat.Builder

Associate a person to a shortcut. Alternatively, setPersons can be used to add multiple persons to a shortcut.

This is an optional field when publishing a new shortcut.

See also
Person

setPersons

Added in 1.1.0
fun setPersons(persons: Array<Person!>): ShortcutInfoCompat.Builder

Sets multiple persons instead of a single person.

setRank

Added in 1.2.0
fun setRank(rank: Int): ShortcutInfoCompat.Builder

Sets rank of a shortcut, which is a non-negative value that's used by the system to sort shortcuts. Lower value means higher importance.

See also
getRank

for details.

setShortLabel

Added in 1.1.0
fun setShortLabel(shortLabel: CharSequence): ShortcutInfoCompat.Builder

Sets the short title of a shortcut.

This is a mandatory field when publishing a new shortcut.

This field is intended to be a concise description of a shortcut.

The recommended maximum length is 10 characters.

setSliceUri

Added in 1.6.0
fun setSliceUri(sliceUri: Uri): ShortcutInfoCompat.Builder

Sets the slice uri for a shortcut. The uri will be used if this shortcuts represents a slice, instead of an intent.