# LauncherApps.ShortcutQuery

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# ShortcutQuery

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/content/pm/LauncherApps.ShortcutQuery "View this page in Java")  

```
open class ShortcutQuery
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                 ||
| ↳ | [android.content.pm.LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#) |

Represents a query passed to[getShortcuts(android.content.pm.LauncherApps.ShortcutQuery,android.os.UserHandle)](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps#getShortcuts(android.content.pm.LauncherApps.ShortcutQuery,%20android.os.UserHandle)).

## Summary

|                                                                                                                                                                       Constants                                                                                                                                                                        ||
|----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [FLAG_GET_KEY_FIELDS_ONLY](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_GET_KEY_FIELDS_ONLY:kotlin.Int) Requests "key" fields only.                                                                             |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [FLAG_MATCH_CACHED](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_CACHED:kotlin.Int) Include cached shortcuts in the result.                                                                               |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [FLAG_MATCH_DYNAMIC](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_DYNAMIC:kotlin.Int) Include dynamic shortcuts in the result.                                                                            |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [FLAG_MATCH_MANIFEST](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_MANIFEST:kotlin.Int) Include manifest shortcuts in the result.                                                                         |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [FLAG_MATCH_PINNED](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED:kotlin.Int) Include pinned shortcuts in the result.                                                                               |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [FLAG_MATCH_PINNED_BY_ANY_LAUNCHER](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED_BY_ANY_LAUNCHER:kotlin.Int) Include all pinned shortcuts by any launchers, not just by the caller, in the result. |

|                                                             Public constructors                                                             ||
|------------------------------------------------------------------------------------------------------------------------------------------|---|
| [ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#ShortcutQuery())`()` <br /> |

|                                                                                                                                                                                                                                                                                                                     Public methods                                                                                                                                                                                                                                                                                                                     ||
|----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#)! | [setActivity](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setActivity(android.content.ComponentName))`(`activity:` `[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)?`)` If non-null, returns only shortcuts associated with the activity; i.                                                                                                                                                                    |
| open[LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#)! | [setChangedSince](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setChangedSince(kotlin.Long))`(`changedSince:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` 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()](https://developer.android.com/reference/kotlin/java/lang/System.html#currentTimeMillis()). |
| open[LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#)  | [setLocusIds](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setLocusIds(kotlin.collections.MutableList))`(`locusIds:` `[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[LocusId](https://developer.android.com/reference/kotlin/android/content/LocusId.html#)!>?`)` If non-null, return only the specified shortcuts by locus ID.                                                                            |
| open[LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#)! | [setPackage](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setPackage(kotlin.String))`(`packageName:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` If non-null, returns only shortcuts from the package.                                                                                                                                                                                                                     |
| open[LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#)! | [setQueryFlags](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setQueryFlags(kotlin.Int))`(`queryFlags:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Set query options.                                                                                                                                                                                                                                                             |
| open[LauncherApps.ShortcutQuery](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#)! | [setShortcutIds](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setShortcutIds(kotlin.collections.MutableList))`(`shortcutIds:` `[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!>?`)` If non-null, return only the specified shortcuts by ID.                                                                                |

## Constants

### FLAG_GET_KEY_FIELDS_ONLY

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val FLAG_GET_KEY_FIELDS_ONLY: Int
```

Requests "key" fields only. See[ShortcutInfo.hasKeyFieldsOnly()](https://developer.android.com/reference/kotlin/android/content/pm/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()](https://developer.android.com/reference/kotlin/android/content/pm/ShortcutInfo#getLastChangedTimestamp())for each shortcut, fetching a shortcut's non-key information only if that shortcut has been updated.  

    Value: 4

**See Also**

- [android.content.pm.ShortcutManager](https://developer.android.com/reference/kotlin/android/content/pm/ShortcutManager)  

### FLAG_MATCH_CACHED

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val FLAG_MATCH_CACHED: Int
```

Include cached shortcuts in the result.  

    Value: 16

### FLAG_MATCH_DYNAMIC

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val FLAG_MATCH_DYNAMIC: Int
```

Include dynamic shortcuts in the result.  

    Value: 1

### FLAG_MATCH_MANIFEST

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val FLAG_MATCH_MANIFEST: Int
```

Include manifest shortcuts in the result.  

    Value: 8

### FLAG_MATCH_PINNED

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val FLAG_MATCH_PINNED: Int
```

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](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED_BY_ANY_LAUNCHER:kotlin.Int)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](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED_BY_ANY_LAUNCHER:kotlin.Int)will be ignored. So use this flag to get own pinned shortcuts.  

    Value: 2

### FLAG_MATCH_PINNED_BY_ANY_LAUNCHER

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val FLAG_MATCH_PINNED_BY_ANY_LAUNCHER: Int
```

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](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED_BY_ANY_LAUNCHER:kotlin.Int)instead.

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

    Value: 1024

## Public constructors

### ShortcutQuery

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
ShortcutQuery()
```

## Public methods

### setActivity

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setActivity(activity: ComponentName?): LauncherApps.ShortcutQuery!
```

If non-null, returns only shortcuts associated with the activity; i.e.[ShortcutInfo](https://developer.android.com/reference/kotlin/android/content/pm/ShortcutInfo)s whose[ShortcutInfo.getActivity()](https://developer.android.com/reference/kotlin/android/content/pm/ShortcutInfo#getActivity())are equal to`activity`.

|                                                                Parameters                                                                 ||
|------------|-------------------------------------------------------------------------------------------------------------------------------|
| `activity` | [ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)?:This value may be`null`. |

### setChangedSince

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setChangedSince(changedSince: Long): LauncherApps.ShortcutQuery!
```

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()](https://developer.android.com/reference/kotlin/java/lang/System.html#currentTimeMillis()).  

### setLocusIds

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setLocusIds(locusIds: MutableList<LocusId!>?): LauncherApps.ShortcutQuery
```

If non-null, return only the specified shortcuts by locus ID. When setting this field, a package name must also be set with[setPackage](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setPackage(kotlin.String)).

|                                                                                                                Parameters                                                                                                                 ||
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `locusIds` | [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[LocusId](https://developer.android.com/reference/kotlin/android/content/LocusId.html#)!\>?:This value may be`null`. |

### setPackage

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setPackage(packageName: String?): LauncherApps.ShortcutQuery!
```

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

|                                                        Parameters                                                         ||
|---------------|------------------------------------------------------------------------------------------------------------|
| `packageName` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

### setQueryFlags

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setQueryFlags(queryFlags: Int): LauncherApps.ShortcutQuery!
```

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

- [FLAG_MATCH_DYNAMIC](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_DYNAMIC:kotlin.Int)
- [FLAG_MATCH_PINNED](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED:kotlin.Int)
- [FLAG_MATCH_MANIFEST](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_MANIFEST:kotlin.Int)
- [FLAG_MATCH_CACHED](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_CACHED:kotlin.Int)
- [FLAG_GET_KEY_FIELDS_ONLY](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_GET_KEY_FIELDS_ONLY:kotlin.Int)

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ||
|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `queryFlags` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Value is either`0`or a combination of[android.content.pm.LauncherApps.ShortcutQuery#FLAG_MATCH_DYNAMIC](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_DYNAMIC:kotlin.Int),[android.content.pm.LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED:kotlin.Int),[android.content.pm.LauncherApps.ShortcutQuery#FLAG_MATCH_MANIFEST](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_MANIFEST:kotlin.Int),[android.content.pm.LauncherApps.ShortcutQuery#FLAG_MATCH_CACHED](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_CACHED:kotlin.Int),[android.content.pm.LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED_BY_ANY_LAUNCHER](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_MATCH_PINNED_BY_ANY_LAUNCHER:kotlin.Int),[android.content.pm.LauncherApps.ShortcutQuery#FLAG_GET_KEY_FIELDS_ONLY](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#FLAG_GET_KEY_FIELDS_ONLY:kotlin.Int), android.content.pm.LauncherApps.ShortcutQuery.FLAG_GET_PERSONS_DATA, and android.content.pm.LauncherApps.ShortcutQuery.FLAG_GET_PERSISTED_DATA |

### setShortcutIds

Added in[API level 25](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setShortcutIds(shortcutIds: MutableList<String!>?): LauncherApps.ShortcutQuery!
```

If non-null, return only the specified shortcuts by ID. When setting this field, a package name must also be set with[setPackage](https://developer.android.com/reference/kotlin/android/content/pm/LauncherApps.ShortcutQuery#setPackage(kotlin.String)).

|                                                                                                              Parameters                                                                                                               ||
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `shortcutIds` | [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!\>?:This value may be`null`. |