Added in API level 25

Builder


class Builder
kotlin.Any
   ↳ android.content.pm.ShortcutInfo.Builder

Builder class for ShortcutInfo objects.

Summary

Public constructors
Builder(context: Context!, id: String!)

Constructor.

Public methods
open ShortcutInfo.Builder
addCapabilityBinding(capability: Capability, capabilityParams: CapabilityParams?)

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

open ShortcutInfo

Creates a ShortcutInfo instance.

open ShortcutInfo.Builder

Sets the target activity.

open ShortcutInfo.Builder

Sets categories for a shortcut.

open ShortcutInfo.Builder
setDisabledMessage(disabledMessage: CharSequence)

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

open ShortcutInfo.Builder

Sets which surfaces a shortcut will be excluded from.

open ShortcutInfo.Builder

Extras that the app can set for any purpose.

open ShortcutInfo.Builder
setIcon(icon: Icon!)

Sets an icon of a shortcut.

open ShortcutInfo.Builder
setIntent(intent: Intent)

Sets the intent of a shortcut.

open ShortcutInfo.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.

open ShortcutInfo.Builder
setLocusId(locusId: LocusId)

Sets the LocusId associated with this shortcut.

open ShortcutInfo.Builder

Sets the text of a shortcut.

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

open ShortcutInfo.Builder
setPerson(person: Person)

Add a person that is relevant to this shortcut.

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

Sets multiple persons instead of a single person.

open ShortcutInfo.Builder
setRank(rank: Int)

"Rank" of a shortcut, which is a non-negative value that's used by the launcher app to sort shortcuts.

open ShortcutInfo.Builder

Sets the short title of a shortcut.

open ShortcutInfo.Builder
setStartingTheme(themeResId: Int)

Sets a theme resource id for the splash screen.

Public constructors

Builder

Added in API level 25
Builder(
    context: Context!,
    id: String!)

Constructor.

Parameters
context Context!: Client context.
id String!: ID of the shortcut.

Public methods

addCapabilityBinding

Added in API level 33
open fun addCapabilityBinding(
    capability: Capability,
    capabilityParams: CapabilityParams?
): ShortcutInfo.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 add multiple parameters to the same capability.

Parameters
capability Capability: Capability associated with the shortcut. This value cannot be null.
capabilityParams CapabilityParams?: Optional CapabilityParams associated with given capability. This value may be null.
Return
ShortcutInfo.Builder This value cannot be null.

build

Added in API level 25
open fun build(): ShortcutInfo

Creates a ShortcutInfo instance.

Return
ShortcutInfo This value cannot be null.

setActivity

Added in API level 25
open fun setActivity(activity: ComponentName): ShortcutInfo.Builder

Sets the target activity. A shortcut will be shown along with this activity's icon on the launcher. When selecting a target activity, keep the following in mind:

Parameters
activity ComponentName: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setCategories

Added in API level 25
open fun setCategories(categories: MutableSet<String!>!): ShortcutInfo.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.

Return
ShortcutInfo.Builder This value cannot be null.

setDisabledMessage

Added in API level 25
open fun setDisabledMessage(disabledMessage: CharSequence): ShortcutInfo.Builder

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

Parameters
disabledMessage CharSequence: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setExcludedFromSurfaces

Added in API level 33
open fun setExcludedFromSurfaces(surfaces: Int): ShortcutInfo.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: android.content.pm.ShortcutManager#pushDynamicShortcut(android.content.pm.ShortcutInfo), android.content.pm.ShortcutManager#addDynamicShortcuts(List), and android.content.pm.ShortcutManager#setDynamicShortcuts(List).

Return
ShortcutInfo.Builder This value cannot be null.

setExtras

Added in API level 25
open fun setExtras(extras: PersistableBundle): ShortcutInfo.Builder

Extras that the app can set for any purpose.

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

Parameters
extras PersistableBundle: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setIcon

Added in API level 25
open fun setIcon(icon: Icon!): ShortcutInfo.Builder

Sets an icon of a shortcut.

Icons are not available on ShortcutInfo instances returned by ShortcutManager or LauncherApps. The default launcher app can use LauncherApps.getShortcutIconDrawable(ShortcutInfo, int) or LauncherApps.getShortcutBadgedIconDrawable(ShortcutInfo, int) to fetch shortcut icons.

Tints set with Icon.setTint or Icon.setTintList are not supported and will be ignored.

Only icons created with Icon.createWithBitmap(Bitmap), Icon.createWithAdaptiveBitmap(Bitmap) and android.graphics.drawable.Icon#createWithResource are supported. Other types, such as URI-based icons, are not supported.

Return
ShortcutInfo.Builder This value cannot be null.

setIntent

Added in API level 25
open fun setIntent(intent: Intent): ShortcutInfo.Builder

Sets the intent of a shortcut. Alternatively, setIntents(android.content.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 with ShortcutManager.addDynamicShortcuts(List) or ShortcutManager.setDynamicShortcuts(List).

A shortcut can launch any intent that the publisher app has permission to launch. For example, a shortcut can launch an unexported activity within the publisher app. A shortcut intent doesn't have to point at the target activity.

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

Parameters
intent Intent: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setIntents

Added in API level 25
open fun setIntents(intents: Array<Intent!>): ShortcutInfo.Builder

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

Parameters
intents Array<Intent!>: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setLocusId

Added in API level 29
open fun setLocusId(locusId: LocusId): ShortcutInfo.Builder

Sets the LocusId associated with this shortcut.

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

Parameters
locusId LocusId: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setLongLabel

Added in API level 25
open fun setLongLabel(longLabel: CharSequence): ShortcutInfo.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.

Parameters
longLabel CharSequence: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setLongLived

Added in API level 29
open fun setLongLived(longLived: Boolean): ShortcutInfo.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.

Return
ShortcutInfo.Builder This value cannot be null.

setPerson

Added in API level 29
open fun setPerson(person: Person): ShortcutInfo.Builder

Add a person that is relevant to this shortcut. Alternatively, setPersons(android.app.Person[]) can be used to add multiple persons to a shortcut.

This is an optional field, but the addition of person may cause this shortcut to appear more prominently in the user interface (e.g. ShareSheet).

A person should usually contain a uri in order to benefit from the ranking boost. However, even if no uri is provided, it's beneficial to provide people in the shortcut, such that listeners and voice only devices can announce and handle them properly.

Parameters
person Person: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setPersons

Added in API level 29
open fun setPersons(persons: Array<Person!>): ShortcutInfo.Builder

Sets multiple persons instead of a single person.

Parameters
persons Array<Person!>: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setRank

Added in API level 25
open fun setRank(rank: Int): ShortcutInfo.Builder

"Rank" of a shortcut, which is a non-negative value that's used by the launcher app to sort shortcuts. See ShortcutInfo.getRank() for details.

Return
ShortcutInfo.Builder This value cannot be null.

setShortLabel

Added in API level 25
open fun setShortLabel(shortLabel: CharSequence): ShortcutInfo.Builder

Sets the short title of a shortcut.

This is a mandatory field when publishing a new shortcut with ShortcutManager.addDynamicShortcuts(List) or ShortcutManager.setDynamicShortcuts(List).

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

The recommended maximum length is 10 characters.

Parameters
shortLabel CharSequence: This value cannot be null.
Return
ShortcutInfo.Builder This value cannot be null.

setStartingTheme

Added in API level 31
open fun setStartingTheme(themeResId: Int): ShortcutInfo.Builder

Sets a theme resource id for the splash screen.

Return
ShortcutInfo.Builder This value cannot be null.