LauncherApps.ShortcutQuery


public static class LauncherApps.ShortcutQuery
extends Object

java.lang.Object
   ↳ android.content.pm.LauncherApps.ShortcutQuery


Represents a query passed to LauncherApps.getShortcuts(android.content.pm.LauncherApps.ShortcutQuery, android.os.UserHandle).

Summary

Constants

int FLAG_GET_KEY_FIELDS_ONLY

Requests "key" fields only.

int FLAG_MATCH_CACHED

Include cached shortcuts in the result.

int FLAG_MATCH_DYNAMIC

Include dynamic shortcuts in the result.

int FLAG_MATCH_MANIFEST

Include manifest shortcuts in the result.

int FLAG_MATCH_PINNED

Include pinned shortcuts in the result.

int FLAG_MATCH_PINNED_BY_ANY_LAUNCHER

Include all pinned shortcuts by any launchers, not just by the caller, in the result.

Public constructors

ShortcutQuery()

Public methods

LauncherApps.ShortcutQuery setActivity(ComponentName activity)

If non-null, returns only shortcuts associated with the activity; i.e.

LauncherApps.ShortcutQuery setChangedSince(long changedSince)

If non-zero, returns only shortcuts that have been added or updated since the given timestamp, expressed in milliseconds since the Epoch—see System#currentTimeMillis().

LauncherApps.ShortcutQuery setLocusIds(List<LocusId> locusIds)

If non-null, return only the specified shortcuts by locus ID.

LauncherApps.ShortcutQuery setPackage(String packageName)

If non-null, returns only shortcuts from the package.

LauncherApps.ShortcutQuery setQueryFlags(int queryFlags)

Set query options.

LauncherApps.ShortcutQuery setShortcutIds(List<String> shortcutIds)

If non-null, return only the specified shortcuts by ID.

Inherited methods

Constants

FLAG_GET_KEY_FIELDS_ONLY

Added in API level 25
public static final int FLAG_GET_KEY_FIELDS_ONLY

Requests "key" fields only. See ShortcutInfo#hasKeyFieldsOnly()'s javadoc to see which fields fields "key". This allows quicker access to shortcut information in order to determine whether the caller's in-memory cache needs to be updated.

Typically, launcher applications cache all or most shortcut information in memory in order to show shortcuts without a delay. When a given launcher application wants to update its cache, such as when its process restarts, it can fetch shortcut information with this flag. The application can then check ShortcutInfo#getLastChangedTimestamp() for each shortcut, fetching a shortcut's non-key information only if that shortcut has been updated.

See also:

Constant Value: 4 (0x00000004)

FLAG_MATCH_CACHED

Added in API level 30
public static final int FLAG_MATCH_CACHED

Include cached shortcuts in the result.

Constant Value: 16 (0x00000010)

FLAG_MATCH_DYNAMIC

Added in API level 25
public static final int FLAG_MATCH_DYNAMIC

Include dynamic shortcuts in the result.

Constant Value: 1 (0x00000001)

FLAG_MATCH_MANIFEST

Added in API level 25
public static final int FLAG_MATCH_MANIFEST

Include manifest shortcuts in the result.

Constant Value: 8 (0x00000008)

FLAG_MATCH_PINNED

Added in API level 25
public static final int FLAG_MATCH_PINNED

Include pinned shortcuts in the result.

If you are the selected assistant app, and wishes to fetch all shortcuts that the user owns on the launcher (or by other launchers, in case the user has multiple), use FLAG_MATCH_PINNED_BY_ANY_LAUNCHER instead.

If you're a regular launcher app, there's no way to get shortcuts pinned by other launchers, and FLAG_MATCH_PINNED_BY_ANY_LAUNCHER will be ignored. So use this flag to get own pinned shortcuts.

Constant Value: 2 (0x00000002)

FLAG_MATCH_PINNED_BY_ANY_LAUNCHER

Added in API level 28
public static final int FLAG_MATCH_PINNED_BY_ANY_LAUNCHER

Include all pinned shortcuts by any launchers, not just by the caller, in the result.

The caller must be the selected assistant app to use this flag, or have the system ACCESS_SHORTCUTS permission.

If you are the selected assistant app, and wishes to fetch all shortcuts that the user owns on the launcher (or by other launchers, in case the user has multiple), use FLAG_MATCH_PINNED_BY_ANY_LAUNCHER instead.

If you're a regular launcher app (or any app that's not the selected assistant app) then this flag will be ignored.

Constant Value: 1024 (0x00000400)

Public constructors

ShortcutQuery

Added in API level 25
public ShortcutQuery ()

Public methods

setActivity

Added in API level 25
public LauncherApps.ShortcutQuery setActivity (ComponentName activity)

If non-null, returns only shortcuts associated with the activity; i.e. ShortcutInfos whose ShortcutInfo#getActivity() are equal to activity.

Parameters
activity ComponentName: This value may be null.

Returns
LauncherApps.ShortcutQuery

setChangedSince

Added in API level 25
public LauncherApps.ShortcutQuery setChangedSince (long changedSince)

If non-zero, returns only shortcuts that have been added or updated since the given timestamp, expressed in milliseconds since the Epoch—see System#currentTimeMillis().

Parameters
changedSince long

Returns
LauncherApps.ShortcutQuery

setLocusIds

Added in API level 30
public LauncherApps.ShortcutQuery setLocusIds (List<LocusId> locusIds)

If non-null, return only the specified shortcuts by locus ID. When setting this field, a package name must also be set with setPackage(String).

Parameters
locusIds List: This value may be null.

Returns
LauncherApps.ShortcutQuery

setPackage

Added in API level 25
public LauncherApps.ShortcutQuery setPackage (String packageName)

If non-null, returns only shortcuts from the package.

Parameters
packageName String: This value may be null.

Returns
LauncherApps.ShortcutQuery

setQueryFlags

Added in API level 25
public LauncherApps.ShortcutQuery setQueryFlags (int queryFlags)

Set query options. At least one of the MATCH flags should be set. Otherwise, no shortcuts will be returned.

Parameters
queryFlags int: Value is either 0 or a combination of FLAG_MATCH_DYNAMIC, FLAG_MATCH_PINNED, FLAG_MATCH_MANIFEST, FLAG_MATCH_CACHED, FLAG_MATCH_PINNED_BY_ANY_LAUNCHER, FLAG_GET_KEY_FIELDS_ONLY, android.content.pm.LauncherApps.ShortcutQuery.FLAG_GET_PERSONS_DATA, and android.content.pm.LauncherApps.ShortcutQuery.FLAG_GET_PERSISTED_DATA

Returns
LauncherApps.ShortcutQuery

setShortcutIds

Added in API level 25
public LauncherApps.ShortcutQuery setShortcutIds (List<String> shortcutIds)

If non-null, return only the specified shortcuts by ID. When setting this field, a package name must also be set with setPackage(String).

Parameters
shortcutIds List: This value may be null.

Returns
LauncherApps.ShortcutQuery