ShortcutInfoCompat.Builder
public
static
class
ShortcutInfoCompat.Builder
extends Object
java.lang.Object | |
↳ | androidx.core.content.pm.ShortcutInfoCompat.Builder |
Builder class for ShortcutInfoCompat
objects.
Summary
Public constructors | |
---|---|
Builder(Context context, String id)
|
Public methods | |
---|---|
ShortcutInfoCompat
|
build()
Creates a |
ShortcutInfoCompat.Builder
|
setActivity(ComponentName activity)
Sets the target activity. |
ShortcutInfoCompat.Builder
|
setAlwaysBadged()
Badges the icon before passing it over to the Launcher. |
ShortcutInfoCompat.Builder
|
setCategories(Set<String> categories)
Sets categories for a shortcut. |
ShortcutInfoCompat.Builder
|
setDisabledMessage(CharSequence disabledMessage)
Sets the message that should be shown when the user attempts to start a shortcut that is disabled. |
ShortcutInfoCompat.Builder
|
setExtras(PersistableBundle extras)
Extras that the app can set for any purpose. |
ShortcutInfoCompat.Builder
|
setIcon(IconCompat icon)
Sets an icon of a shortcut. |
ShortcutInfoCompat.Builder
|
setIntent(Intent intent)
Sets the intent of a shortcut. |
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. |
ShortcutInfoCompat.Builder
|
setIsConversation()
Sets the corresponding fields indicating this shortcut is aimed for conversation. |
ShortcutInfoCompat.Builder
|
setLocusId(LocusIdCompat locusId)
Sets the |
ShortcutInfoCompat.Builder
|
setLongLabel(CharSequence longLabel)
Sets the text of a shortcut. |
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). |
ShortcutInfoCompat.Builder
|
setLongLived()
This method is deprecated. Use {@ink #setLongLived(boolean)) instead. |
ShortcutInfoCompat.Builder
|
setPerson(Person person)
Associate a person to a shortcut. |
ShortcutInfoCompat.Builder
|
setPersons(Person[] persons)
Sets multiple persons instead of a single person. |
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. |
ShortcutInfoCompat.Builder
|
setShortLabel(CharSequence shortLabel)
Sets the short title of a shortcut. |
Inherited methods | |
---|---|
Public constructors
Public methods
build
public ShortcutInfoCompat build ()
Creates a ShortcutInfoCompat
instance.
Returns | |
---|---|
ShortcutInfoCompat |
setActivity
public ShortcutInfoCompat.Builder setActivity (ComponentName activity)
Sets the target activity. A shortcut will be shown along with this activity's icon on the launcher.
Parameters | |
---|---|
activity |
ComponentName |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setAlwaysBadged
public 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.
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setCategories
public ShortcutInfoCompat.Builder setCategories (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.
Parameters | |
---|---|
categories |
Set |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setDisabledMessage
public ShortcutInfoCompat.Builder setDisabledMessage (CharSequence disabledMessage)
Sets the message that should be shown when the user attempts to start a shortcut that is disabled.
Parameters | |
---|---|
disabledMessage |
CharSequence |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setExtras
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.getExtras()
.
Parameters | |
---|---|
extras |
PersistableBundle |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setIcon
public ShortcutInfoCompat.Builder setIcon (IconCompat icon)
Sets an icon of a shortcut.
Parameters | |
---|---|
icon |
IconCompat |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setIntent
public ShortcutInfoCompat.Builder setIntent (Intent intent)
Sets the intent of a shortcut. Alternatively, 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.
Parameters | |
---|---|
intent |
Intent |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setIntents
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 TaskStackBuilder
to build
intents. The last element in the list represents the only intent that doesn't place
an activity on the back stack.
Parameters | |
---|---|
intents |
Intent |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setIsConversation
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 build()
Additionally, the shortcut will be long-lived.
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setLocusId
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
ContentCaptureContext
) so the device's intelligence
services can correlate them.
Parameters | |
---|---|
locusId |
LocusIdCompat |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setLongLabel
public ShortcutInfoCompat.Builder setLongLabel (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.
Parameters | |
---|---|
longLabel |
CharSequence |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setLongLived
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.
Parameters | |
---|---|
longLived |
boolean |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setLongLived
public ShortcutInfoCompat.Builder setLongLived ()
This method is deprecated.
Use {@ink #setLongLived(boolean)) instead.
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setPerson
public ShortcutInfoCompat.Builder setPerson (Person person)
Associate a person to a shortcut. Alternatively, setPersons(Person[])
can be
used to add multiple persons to a shortcut.
This is an optional field when publishing a new shortcut.
Parameters | |
---|---|
person |
Person |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setPersons
public ShortcutInfoCompat.Builder setPersons (Person[] persons)
Sets multiple persons instead of a single person.
Parameters | |
---|---|
persons |
Person |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
setRank
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.
Parameters | |
---|---|
rank |
int |
Returns | |
---|---|
ShortcutInfoCompat.Builder |
See also:
setShortLabel
public ShortcutInfoCompat.Builder setShortLabel (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.
Parameters | |
---|---|
shortLabel |
CharSequence |
Returns | |
---|---|
ShortcutInfoCompat.Builder |