ShortcutInfoCompat.Builder
public class ShortcutInfoCompat.Builder
Builder class for ShortcutInfoCompat objects.
Summary
Public methods |
|
|---|---|
@NonNull ShortcutInfoCompat.Builder |
addCapabilityBinding(@NonNull String capability)Associates a shortcut with a capability without any parameters. |
@NonNull ShortcutInfoCompat.Builder |
addCapabilityBinding(Associates a shortcut with a capability, and a parameter of that capability. |
@NonNull ShortcutInfoCompat |
build()Creates a |
@NonNull ShortcutInfoCompat.Builder |
setActivity(@NonNull ComponentName activity)Sets the target activity. |
@NonNull ShortcutInfoCompat.Builder |
Badges the icon before passing it over to the Launcher. |
@NonNull ShortcutInfoCompat.Builder |
setCategories(@NonNull Set<String> categories)Sets categories for a shortcut. |
@NonNull ShortcutInfoCompat.Builder |
setDisabledMessage(@NonNull CharSequence disabledMessage)Sets the message that should be shown when the user attempts to start a shortcut that is disabled. |
@NonNull ShortcutInfoCompat.Builder |
setExcludedFromSurfaces(int surfaces)Sets which surfaces a shortcut will be excluded from. |
@NonNull ShortcutInfoCompat.Builder |
setExtras(@NonNull PersistableBundle extras)Extras that the app can set for any purpose. |
@NonNull ShortcutInfoCompat.Builder |
setIcon(IconCompat icon)Sets an icon of a shortcut. |
@NonNull ShortcutInfoCompat.Builder |
Sets the intent of a shortcut. |
@NonNull ShortcutInfoCompat.Builder |
setIntents(@NonNull Intent[] intents)Sets multiple intents instead of a single intent, in order to launch an activity with other activities in back stack. |
@NonNull ShortcutInfoCompat.Builder |
Sets the corresponding fields indicating this shortcut is aimed for conversation. |
@NonNull ShortcutInfoCompat.Builder |
setLocusId(@Nullable LocusIdCompat locusId)Sets the |
@NonNull ShortcutInfoCompat.Builder |
setLongLabel(@NonNull CharSequence longLabel)Sets the text of a shortcut. |
@NonNull ShortcutInfoCompat.Builder |
This method is deprecated. Use {@ink #setLongLived(boolean)) instead. |
@NonNull 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). |
@NonNull ShortcutInfoCompat.Builder |
Associate a person to a shortcut. |
@NonNull ShortcutInfoCompat.Builder |
setPersons(@NonNull Person[] persons)Sets multiple persons instead of a single person. |
@NonNull 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. |
@NonNull ShortcutInfoCompat.Builder |
setShortLabel(@NonNull CharSequence shortLabel)Sets the short title of a shortcut. |
@NonNull ShortcutInfoCompat.Builder |
setSliceUri(@NonNull Uri sliceUri)Sets the slice uri for a shortcut. |
Public constructors
Public methods
addCapabilityBinding
public @NonNull ShortcutInfoCompat.Builder addCapabilityBinding(@NonNull 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.
addCapabilityBinding
public @NonNull ShortcutInfoCompat.Builder addCapabilityBinding(
@NonNull String capability,
@NonNull String parameter,
@NonNull List<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 | |
|---|---|
@NonNull String capability |
capability associated with the shortcut. e.g. actions.intent .START_EXERCISE. |
@NonNull String parameter |
the parameter associated with the capability. e.g. exercise.name. |
@NonNull List<String> 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. |
build
public @NonNull ShortcutInfoCompat build()
Creates a ShortcutInfoCompat instance.
setActivity
public @NonNull ShortcutInfoCompat.Builder setActivity(@NonNull ComponentName activity)
Sets the target activity. A shortcut will be shown along with this activity's icon on the launcher.
| See also | |
|---|---|
getActivity |
|
setActivity |
setAlwaysBadged
public @NonNull ShortcutInfoCompat.Builder setAlwaysBadged()
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
public @NonNull ShortcutInfoCompat.Builder setCategories(@NonNull Set<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 | |
|---|---|
getCategories |
setDisabledMessage
public @NonNull ShortcutInfoCompat.Builder setDisabledMessage(@NonNull CharSequence disabledMessage)
Sets the message that should be shown when the user attempts to start a shortcut that is disabled.
| See also | |
|---|---|
getDisabledMessage |
setExcludedFromSurfaces
public @NonNull 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 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
public @NonNull ShortcutInfoCompat.Builder setExtras(@NonNull 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 getExtras.
| See also | |
|---|---|
getExtras |
setIcon
public @NonNull ShortcutInfoCompat.Builder setIcon(IconCompat icon)
Sets an icon of a shortcut.
setIntent
public @NonNull ShortcutInfoCompat.Builder setIntent(@NonNull Intent intent)
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
public @NonNull ShortcutInfoCompat.Builder setIntents(@NonNull Intent[] intents)
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
public @NonNull 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 getId will be added upon build
Additionally, the shortcut will be long-lived.
| See also | |
|---|---|
setLongLived |
setLocusId
public @NonNull ShortcutInfoCompat.Builder setLocusId(@Nullable LocusIdCompat locusId)
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
public @NonNull ShortcutInfoCompat.Builder setLongLabel(@NonNull 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.
setLongLived
public @NonNull 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.
setPerson
public @NonNull ShortcutInfoCompat.Builder setPerson(@NonNull Person person)
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
public @NonNull ShortcutInfoCompat.Builder setPersons(@NonNull Person[] persons)
Sets multiple persons instead of a single person.
setRank
public @NonNull 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 | |
|---|---|
getRank |
for details. |
setShortLabel
public @NonNull ShortcutInfoCompat.Builder setShortLabel(@NonNull 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.
setSliceUri
public @NonNull ShortcutInfoCompat.Builder setSliceUri(@NonNull Uri sliceUri)
Sets the slice uri for a shortcut. The uri will be used if this shortcuts represents a slice, instead of an intent.