public class

ShortcutInfoCompat.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.core.content.pm.ShortcutInfoCompat.Builder

Overview

Builder class for ShortcutInfoCompat objects.

Summary

Constructors
publicBuilder(Context context, ShortcutInfo shortcutInfo)

publicBuilder(Context context, java.lang.String id)

publicBuilder(ShortcutInfoCompat shortcutInfo)

Methods
public ShortcutInfoCompat.BuilderaddCapabilityBinding(java.lang.String capability)

Associates a shortcut with a capability without any parameters.

public ShortcutInfoCompat.BuilderaddCapabilityBinding(java.lang.String capability, java.lang.String parameter, java.util.List<java.lang.String> parameterValues)

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

public ShortcutInfoCompatbuild()

Creates a ShortcutInfoCompat instance.

public ShortcutInfoCompat.BuildersetActivity(ComponentName activity)

Sets the target activity.

public ShortcutInfoCompat.BuildersetAlwaysBadged()

Badges the icon before passing it over to the Launcher.

public ShortcutInfoCompat.BuildersetCategories(java.util.Set<java.lang.String> categories)

Sets categories for a shortcut.

public ShortcutInfoCompat.BuildersetDisabledMessage(java.lang.CharSequence disabledMessage)

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

public ShortcutInfoCompat.BuildersetExcludedFromSurfaces(int surfaces)

Sets which surfaces a shortcut will be excluded from.

public ShortcutInfoCompat.BuildersetExtras(PersistableBundle extras)

Extras that the app can set for any purpose.

public ShortcutInfoCompat.BuildersetIcon(IconCompat icon)

Sets an icon of a shortcut.

public ShortcutInfoCompat.BuildersetIntent(Intent intent)

Sets the intent of a shortcut.

public ShortcutInfoCompat.BuildersetIntents(Intent intents[])

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

public ShortcutInfoCompat.BuildersetIsConversation()

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

public ShortcutInfoCompat.BuildersetLocusId(LocusIdCompat locusId)

Sets the LocusIdCompat associated with this shortcut.

public ShortcutInfoCompat.BuildersetLongLabel(java.lang.CharSequence longLabel)

Sets the text of a shortcut.

public ShortcutInfoCompat.BuildersetLongLived()

public ShortcutInfoCompat.BuildersetLongLived(boolean longLived)

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

public ShortcutInfoCompat.BuildersetPerson(Person person)

Associate a person to a shortcut.

public ShortcutInfoCompat.BuildersetPersons(Person persons[])

Sets multiple persons instead of a single person.

public ShortcutInfoCompat.BuildersetRank(int rank)

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

public ShortcutInfoCompat.BuildersetShortLabel(java.lang.CharSequence shortLabel)

Sets the short title of a shortcut.

public ShortcutInfoCompat.BuildersetSliceUri(Uri sliceUri)

Sets the slice uri for a shortcut.

public ShortcutInfoCompat.BuildersetTransientExtras(Bundle transientExtras)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Context context, java.lang.String id)

public Builder(ShortcutInfoCompat shortcutInfo)

public Builder(Context context, ShortcutInfo shortcutInfo)

Methods

public ShortcutInfoCompat.Builder setShortLabel(java.lang.CharSequence shortLabel)

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.

public ShortcutInfoCompat.Builder setLongLabel(java.lang.CharSequence longLabel)

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.

public ShortcutInfoCompat.Builder setDisabledMessage(java.lang.CharSequence disabledMessage)

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

See also: ShortcutInfo

public ShortcutInfoCompat.Builder setIntent(Intent intent)

Sets the intent of a shortcut. Alternatively, ShortcutInfoCompat.Builder.setIntents(Intent[]) 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.

public ShortcutInfoCompat.Builder setIntents(Intent intents[])

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

Sets an icon of a shortcut.

public ShortcutInfoCompat.Builder setLocusId(LocusIdCompat locusId)

Sets the LocusIdCompat associated with this shortcut.

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

public ShortcutInfoCompat.Builder setIsConversation()

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

If the shortcut is not associated with a LocusIdCompat, a LocusIdCompat based on ShortcutInfoCompat.getId() will be added upon ShortcutInfoCompat.Builder.build()

Additionally, the shortcut will be long-lived.

See also: ShortcutInfoCompat.Builder.setLongLived(boolean)

public ShortcutInfoCompat.Builder setActivity(ComponentName activity)

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

See also: ShortcutInfo

public ShortcutInfoCompat.Builder setAlwaysBadged()

Badges the icon before passing it over to the Launcher.

Launcher automatically badges ShortcutInfo, so only the legacy shortcut icon, 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: ShortcutInfoCompat.Builder.setActivity(ComponentName)

public ShortcutInfoCompat.Builder setPerson(Person person)

Associate a person to a shortcut. Alternatively, ShortcutInfoCompat.Builder.setPersons(Person[]) can be used to add multiple persons to a shortcut.

This is an optional field when publishing a new shortcut.

See also: Person

public ShortcutInfoCompat.Builder setPersons(Person persons[])

Sets multiple persons instead of a single person.

public ShortcutInfoCompat.Builder setCategories(java.util.Set<java.lang.String> categories)

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: ShortcutInfo

public ShortcutInfoCompat.Builder setLongLived()

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

public ShortcutInfoCompat.Builder setLongLived(boolean longLived)

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.

public ShortcutInfoCompat.Builder setExcludedFromSurfaces(int surfaces)

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

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

public ShortcutInfoCompat.Builder setRank(int rank)

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: for details.

public ShortcutInfoCompat.Builder setExtras(PersistableBundle extras)

Extras that the app can set for any purpose.

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

See also: ShortcutInfo

public ShortcutInfoCompat.Builder setTransientExtras(Bundle transientExtras)

public ShortcutInfoCompat.Builder addCapabilityBinding(java.lang.String capability)

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: capability associated with the shortcut. e.g. actions.intent .START_EXERCISE.

public ShortcutInfoCompat.Builder addCapabilityBinding(java.lang.String capability, java.lang.String parameter, java.util.List<java.lang.String> parameterValues)

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: capability associated with the shortcut. e.g. actions.intent .START_EXERCISE.
parameter: the parameter associated with the capability. e.g. exercise.name.
parameterValues: 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.

public ShortcutInfoCompat.Builder setSliceUri(Uri sliceUri)

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

public ShortcutInfoCompat build()

Creates a ShortcutInfoCompat instance.