public final class ShortcutInfo extends Object implements Parcelable
ShortcutManager
.ShortcutManager
Modifier and Type | Class and Description |
---|---|
static class |
ShortcutInfo.Builder
Builder class for
ShortcutInfo objects. |
static interface |
ShortcutInfo.CloneFlags |
static interface |
ShortcutInfo.ShortcutFlags |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static int |
CLONE_REMOVE_FOR_CREATOR |
static int |
CLONE_REMOVE_FOR_LAUNCHER |
static int |
CLONE_REMOVE_NON_KEY_INFO |
static int |
CLONE_REMOVE_RES_NAMES |
static Parcelable.Creator<ShortcutInfo> |
CREATOR |
static int |
FLAG_DISABLED |
static int |
FLAG_DYNAMIC |
static int |
FLAG_HAS_ICON_FILE |
static int |
FLAG_HAS_ICON_RES |
static int |
FLAG_IMMUTABLE |
static int |
FLAG_KEY_FIELDS_ONLY |
static int |
FLAG_MANIFEST |
static int |
FLAG_PINNED |
static int |
FLAG_STRINGS_RESOLVED |
static int |
RANK_NOT_SET |
static String |
SHORTCUT_CATEGORY_CONVERSATION
Shortcut category for messaging related actions, such as chat.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
ShortcutInfo(int userId,
String id,
String packageName,
ComponentName activity,
Icon icon,
CharSequence title,
int titleResId,
String titleResName,
CharSequence text,
int textResId,
String textResName,
CharSequence disabledMessage,
int disabledMessageResId,
String disabledMessageResName,
Set<String> categories,
Intent[] intentsWithExtras,
int rank,
PersistableBundle extras,
long lastChangedTimestamp,
int flags,
int iconResId,
String iconResName,
String bitmapPath) |
Modifier and Type | Method and Description |
---|---|
void |
addFlags(int flags) |
void |
clearFlags(int flags) |
void |
clearIcon() |
void |
clearImplicitRankAndRankChangedFlag() |
ShortcutInfo |
clone(int cloneFlags)
Copy a
ShortcutInfo , optionally removing fields. |
void |
copyNonNullFieldsFrom(ShortcutInfo source)
Copy non-null/zero fields from another
ShortcutInfo . |
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
void |
enforceMandatoryFields()
Throws if any of the mandatory fields is not set.
|
void |
ensureUpdatableWith(ShortcutInfo source) |
ComponentName |
getActivity()
Return the target activity.
|
String |
getBitmapPath() |
Set<String> |
getCategories()
Return the shortcut's categories.
|
CharSequence |
getDisabledMessage()
Return the message that should be shown when the user attempts to start a shortcut
that is disabled.
|
String |
getDisabledMessageResName() |
int |
getDisabledMessageResourceId() |
PersistableBundle |
getExtras()
Extras that the app can set for any purpose.
|
int |
getFlags() |
Icon |
getIcon()
Returns the shortcut icon.
|
String |
getIconResName() |
int |
getIconResourceId()
Get the resource ID for the icon, valid only when
hasIconResource() } is true. |
String |
getId()
Returns the ID of a shortcut.
|
int |
getImplicitRank() |
Intent |
getIntent()
Returns the intent that is executed when the user selects this shortcut.
|
PersistableBundle[] |
getIntentPersistableExtrases()
The extras in the intents.
|
Intent[] |
getIntents()
Return the intent set with
ShortcutInfo.Builder.setIntents(Intent[]) . |
Intent[] |
getIntentsNoExtras()
Return "raw" intents, which is the original intents without the extras.
|
static IllegalArgumentException |
getInvalidIconException() |
long |
getLastChangedTimestamp()
Last time when any of the fields was updated.
|
CharSequence |
getLongLabel()
Return the long description of a shortcut.
|
int |
getLongLabelResourceId() |
String |
getPackage()
Return the package name of the publisher app.
|
int |
getRank()
"Rank" of a shortcut, which is a non-negative, sequential value that's unique for each
getActivity() for each of the two types of shortcuts (static and dynamic). |
static String |
getResourceEntryName(String fullResourceName)
Extract the entry name from a fully-donated resource name.
|
static String |
getResourcePackageName(String fullResourceName)
Extract the package name from a fully-donated resource name.
|
static String |
getResourceTypeAndEntryName(String fullResourceName)
Extract the type name + the entry name from a fully-donated resource name.
|
static String |
getResourceTypeName(String fullResourceName)
Extract the type name from a fully-donated resource name.
|
CharSequence |
getShortLabel()
Return the short description of a shortcut.
|
int |
getShortLabelResourceId() |
CharSequence |
getText()
Deprecated.
|
int |
getTextResId()
Deprecated.
|
String |
getTextResName() |
CharSequence |
getTitle()
Deprecated.
|
int |
getTitleResId()
Deprecated.
|
String |
getTitleResName() |
UserHandle |
getUserHandle()
UserHandle on which the publisher created this shortcut. |
int |
getUserId() |
boolean |
hasAnyResources() |
boolean |
hasFlags(int flags) |
boolean |
hasIconFile()
Return whether a shortcut's icon is stored as a file.
|
boolean |
hasIconResource()
Return whether a shortcut's icon is a resource in the owning package.
|
boolean |
hasKeyFieldsOnly()
Return whether a shortcut only contains "key" information only or not.
|
boolean |
hasRank() |
boolean |
hasStringResources() |
boolean |
hasStringResourcesResolved() |
boolean |
isAlive() |
boolean |
isDeclaredInManifest()
Return whether a shortcut is static; that is, whether a shortcut is
published from AndroidManifest.xml.
|
boolean |
isDynamic()
Return whether a shortcut is dynamic.
|
boolean |
isEnabled()
Returns
false if a shortcut is disabled with
ShortcutManager.disableShortcuts(java.util.List<java.lang.String>) . |
boolean |
isFloating() |
boolean |
isImmutable()
Return if a shortcut is immutable, in which case it cannot be modified with any of
ShortcutManager APIs. |
boolean |
isManifestShortcut()
Deprecated.
|
boolean |
isOriginallyFromManifest() |
boolean |
isPinned()
Return whether a shortcut is pinned.
|
boolean |
isRankChanged() |
void |
lookupAndFillInResourceIds(Resources res)
Look up resource IDs from the resource names for the icon res and the text fields, and fill
in the resource ID fields.
|
void |
lookupAndFillInResourceNames(Resources res)
Look up resource names from the resource IDs for the icon res and the text fields, and fill
in the resource name fields.
|
static int |
lookUpResourceId(Resources res,
String resourceName,
String resourceType,
String packageName)
Return the resource ID for a given resource ID.
|
static String |
lookUpResourceName(Resources res,
int resId,
boolean withType,
String packageName)
Look up resource name for a given resource ID.
|
void |
replaceFlags(int flags) |
void |
resolveResourceStrings(Resources res)
Load the string resources for the text fields and set them to the actual value fields.
|
void |
setActivity(ComponentName activity) |
void |
setBitmapPath(String bitmapPath) |
void |
setCategories(Set<String> categories)
Replaces the categories.
|
void |
setDisabledMessage(String disabledMessage) |
void |
setDisabledMessageResId(int disabledMessageResId) |
void |
setDisabledMessageResName(String disabledMessageResName) |
void |
setIconResName(String iconResName) |
void |
setIconResourceId(int iconResourceId) |
void |
setImplicitRank(int rank) |
static Intent |
setIntentExtras(Intent intent,
PersistableBundle extras) |
void |
setIntents(Intent[] intents)
Replaces the intent.
|
void |
setRank(int rank) |
void |
setRankChanged() |
void |
setTextResName(String textResName) |
void |
setTimestamp(long value) |
void |
setTitleResName(String titleResName) |
String |
toInsecureString() |
String |
toString()
Return a string representation, intended for logging.
|
void |
updateTimestamp() |
boolean |
usesQuota() |
static Icon |
validateIcon(Icon icon) |
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final int RANK_NOT_SET
public static final int FLAG_DYNAMIC
public static final int FLAG_PINNED
public static final int FLAG_HAS_ICON_RES
public static final int FLAG_HAS_ICON_FILE
public static final int FLAG_KEY_FIELDS_ONLY
public static final int FLAG_MANIFEST
public static final int FLAG_DISABLED
public static final int FLAG_STRINGS_RESOLVED
public static final int FLAG_IMMUTABLE
public static final int CLONE_REMOVE_NON_KEY_INFO
public static final int CLONE_REMOVE_RES_NAMES
public static final int CLONE_REMOVE_FOR_CREATOR
public static final int CLONE_REMOVE_FOR_LAUNCHER
public static final String SHORTCUT_CATEGORY_CONVERSATION
public static final Parcelable.Creator<ShortcutInfo> CREATOR
public ShortcutInfo(int userId, String id, String packageName, ComponentName activity, Icon icon, CharSequence title, int titleResId, String titleResName, CharSequence text, int textResId, String textResName, CharSequence disabledMessage, int disabledMessageResId, String disabledMessageResName, Set<String> categories, Intent[] intentsWithExtras, int rank, PersistableBundle extras, long lastChangedTimestamp, int flags, int iconResId, String iconResName, String bitmapPath)
public void enforceMandatoryFields()
public void resolveResourceStrings(Resources res)
FLAG_STRINGS_RESOLVED
.res
- Resources
for the publisher. Must have been loaded with
PackageManager.getResourcesForApplicationAsUser(java.lang.String, int)
.public static String lookUpResourceName(Resources res, int resId, boolean withType, String packageName)
withType
is false, or with the
type (e.g. "string/text_1").public static String getResourcePackageName(String fullResourceName)
public static String getResourceTypeName(String fullResourceName)
public static String getResourceTypeAndEntryName(String fullResourceName)
public static String getResourceEntryName(String fullResourceName)
public static int lookUpResourceId(Resources res, String resourceName, String resourceType, String packageName)
Resources.getIdentifier(String, String, String)
, except
if resourceName
is an integer then it'll just return its value. (Which also the
aforementioned method would do internally, but not documented, so doing here explicitly.)res
- Resources
for the publisher. Must have been loaded with
PackageManager.getResourcesForApplicationAsUser(java.lang.String, int)
.public void lookupAndFillInResourceNames(Resources res)
res
- Resources
for the publisher. Must have been loaded with
PackageManager.getResourcesForApplicationAsUser(java.lang.String, int)
.public void lookupAndFillInResourceIds(Resources res)
public ShortcutInfo clone(int cloneFlags)
ShortcutInfo
, optionally removing fields.public void ensureUpdatableWith(ShortcutInfo source)
public void copyNonNullFieldsFrom(ShortcutInfo source)
ShortcutInfo
. Only "public" information
will be overwritten. The timestamp will *not* be updated to be consistent with other
setters (and also the clock is not injectable in this file).
- Flags will not change
- mBitmapPath will not change
- Current time will be set to timestampIllegalStateException
- if source is not compatible.public static IllegalArgumentException getInvalidIconException()
public String getId()
Shortcut IDs are unique within each publisher app and must be stable across
devices so that shortcuts will still be valid when restored on a different device.
See ShortcutManager
for details.
public String getPackage()
public ComponentName getActivity()
This has nothing to do with the activity that this shortcut will launch. Launcher apps should show the launcher icon for the returned activity alongside this shortcut.
public void setActivity(ComponentName activity)
public Icon getIcon()
@Deprecated public CharSequence getTitle()
@Deprecated public int getTitleResId()
@Deprecated public CharSequence getText()
@Deprecated public int getTextResId()
public CharSequence getShortLabel()
public int getShortLabelResourceId()
public CharSequence getLongLabel()
public int getLongLabelResourceId()
public CharSequence getDisabledMessage()
public int getDisabledMessageResourceId()
public Set<String> getCategories()
ShortcutInfo.Builder.setCategories(Set)
public Intent getIntent()
Launcher apps cannot see the intent. If a ShortcutInfo
is
obtained via LauncherApps
, then this method will always return null.
Launchers can only start a shortcut intent with LauncherApps.startShortcut(java.lang.String, java.lang.String, android.graphics.Rect, android.os.Bundle, android.os.UserHandle)
.
ShortcutInfo.Builder.setIntent(Intent)
public Intent[] getIntents()
ShortcutInfo.Builder.setIntents(Intent[])
.
Launcher apps cannot see the intents. If a ShortcutInfo
is
obtained via LauncherApps
, then this method will always return null.
Launchers can only start a shortcut intent with LauncherApps.startShortcut(java.lang.String, java.lang.String, android.graphics.Rect, android.os.Bundle, android.os.UserHandle)
.
public Intent[] getIntentsNoExtras()
public PersistableBundle[] getIntentPersistableExtrases()
PersistableBundle
so we can
persist them.public int getRank()
getActivity()
for each of the two types of shortcuts (static and dynamic).
Because static shortcuts and dynamic shortcuts have overlapping ranks, when a launcher app shows shortcuts for an activity, it should first show the static shortcuts, followed by the dynamic shortcuts. Within each of those categories, shortcuts should be sorted by rank in ascending order.
Floating shortcuts, or shortcuts that are neither static nor dynamic, will all
have rank 0, because they aren't sorted.
See the ShortcutManager
's class javadoc for details.
ShortcutInfo.Builder.setRank(int)
public boolean hasRank()
public void setRank(int rank)
public void clearImplicitRankAndRankChangedFlag()
public void setImplicitRank(int rank)
public int getImplicitRank()
public void setRankChanged()
public boolean isRankChanged()
public PersistableBundle getExtras()
public int getUserId()
public UserHandle getUserHandle()
UserHandle
on which the publisher created this shortcut.public long getLastChangedTimestamp()
public int getFlags()
public void replaceFlags(int flags)
public void addFlags(int flags)
public void clearFlags(int flags)
public boolean hasFlags(int flags)
public boolean isDynamic()
public boolean isPinned()
public boolean isDeclaredInManifest()
true
, the shortcut is
also isImmutable()
.
When an app is upgraded and a shortcut is no longer published from AndroidManifest.xml,
this will be set to false
. If the shortcut is not pinned, then it'll disappear.
However, if it's pinned, it will still be visible, isEnabled()
will be
false
and isImmutable()
will be true
.
@Deprecated public boolean isManifestShortcut()
public boolean isFloating()
public boolean isOriginallyFromManifest()
public boolean isImmutable()
ShortcutManager
APIs.
All static shortcuts are immutable. When a static shortcut is pinned and is then
disabled because it doesn't appear in AndroidManifest.xml for a newer version of the
app, isDeclaredInManifest()
returns false
, but the shortcut
is still immutable.
All shortcuts originally published via the ShortcutManager
APIs
are all mutable.
public boolean isEnabled()
false
if a shortcut is disabled with
ShortcutManager.disableShortcuts(java.util.List<java.lang.String>)
.public boolean isAlive()
public boolean usesQuota()
public boolean hasIconResource()
public boolean hasStringResources()
public boolean hasAnyResources()
public boolean hasIconFile()
public boolean hasKeyFieldsOnly()
getId()
getPackage()
getActivity()
getLastChangedTimestamp()
isDynamic()
isPinned()
isDeclaredInManifest()
isImmutable()
isEnabled()
getUserHandle()
For performance reasons, shortcuts passed to
LauncherApps.Callback.onShortcutsChanged(String, List, UserHandle)
as well as those
returned from LauncherApps.getShortcuts(ShortcutQuery, UserHandle)
while using the LauncherApps.ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY
option contain only key
information.
public boolean hasStringResourcesResolved()
public void updateTimestamp()
public void setTimestamp(long value)
public void clearIcon()
public void setIconResourceId(int iconResourceId)
public int getIconResourceId()
hasIconResource()
} is true.public String getBitmapPath()
public void setBitmapPath(String bitmapPath)
public void setDisabledMessageResId(int disabledMessageResId)
public void setDisabledMessage(String disabledMessage)
public String getTitleResName()
public void setTitleResName(String titleResName)
public String getTextResName()
public void setTextResName(String textResName)
public String getDisabledMessageResName()
public void setDisabledMessageResName(String disabledMessageResName)
public String getIconResName()
public void setIconResName(String iconResName)
public void setIntents(Intent[] intents) throws IllegalArgumentException
IllegalArgumentException
- when extra is not compatible with PersistableBundle
.public static Intent setIntentExtras(Intent intent, PersistableBundle extras)
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public String toString()
public String toInsecureString()