Google is committed to advancing racial equity for Black communities. See how.

ShortcutManagerCompat

open class ShortcutManagerCompat
kotlin.Any
   ↳ androidx.core.content.pm.ShortcutManagerCompat

Helper for accessing features in android.content.pm.ShortcutManager.

Summary

Constants
static String

Key to get the shortcut ID from extras of a share intent.

static Int

Include cached shortcuts in the result.

static Int

Include dynamic shortcuts in the result.

static Int

Include manifest shortcuts in the result.

static Int

Include pinned shortcuts in the result.

Public methods
open static Boolean
addDynamicShortcuts(@NonNull context: Context, @NonNull shortcutInfoList: MutableList<ShortcutInfoCompat!>)

Publish the list of dynamic shortcuts.

open static Intent
createShortcutResultIntent(@NonNull context: Context, @NonNull shortcut: ShortcutInfoCompat)

Returns an Intent which can be used by the launcher to pin shortcut.

open static Unit
disableShortcuts(@NonNull context: Context, @NonNull shortcutIds: MutableList<String!>, @Nullable disabledMessage: CharSequence?)

Disable pinned shortcuts, showing the user a custom error message when they try to select the disabled shortcuts.

open static Unit
enableShortcuts(@NonNull context: Context, @NonNull shortcutInfoList: MutableList<ShortcutInfoCompat!>)

Re-enable pinned shortcuts that were previously disabled.

open static MutableList<ShortcutInfoCompat!>
getDynamicShortcuts(@NonNull context: Context)

Return all dynamic shortcuts from the caller app.

open static Int
getIconMaxHeight(@NonNull context: Context)

Return the max height for icons, in pixels.

open static Int
getIconMaxWidth(@NonNull context: Context)

Return the max width for icons, in pixels.

open static Int

open static MutableList<ShortcutInfoCompat!>
getShortcuts(@NonNull context: Context, matchFlags: Int)

Returns ShortcutInfoCompats that match matchFlags.

open static Boolean
isRateLimitingActive(@NonNull context: Context)

Return true when rate-limiting is active for the caller app.

open static Boolean

open static Boolean
pushDynamicShortcut(@NonNull context: Context, @NonNull shortcut: ShortcutInfoCompat)

Publish a single dynamic shortcut.

open static Unit

Delete all dynamic shortcuts from the caller app.

open static Unit
removeDynamicShortcuts(@NonNull context: Context, @NonNull shortcutIds: MutableList<String!>)

Delete dynamic shortcuts by ID.

open static Unit
removeLongLivedShortcuts(@NonNull context: Context, @NonNull shortcutIds: MutableList<String!>)

Delete long lived shortcuts by ID.

open static Unit
reportShortcutUsed(@NonNull context: Context, @NonNull shortcutId: String)

Apps that publish shortcuts should call this method whenever the user selects the shortcut containing the given ID or when the user completes an action in the app that is equivalent to selecting the shortcut.

open static Boolean
requestPinShortcut(@NonNull context: Context, @NonNull shortcut: ShortcutInfoCompat, @Nullable callback: IntentSender?)

Request to create a pinned shortcut.

open static Boolean
setDynamicShortcuts(@NonNull context: Context, @NonNull shortcutInfoList: MutableList<ShortcutInfoCompat!>)

Publish the list of shortcuts.

open static Boolean
updateShortcuts(@NonNull context: Context, @NonNull shortcutInfoList: MutableList<ShortcutInfoCompat!>)

Update all existing shortcuts with the same IDs.

Constants

EXTRA_SHORTCUT_ID

static val EXTRA_SHORTCUT_ID: String

Key to get the shortcut ID from extras of a share intent. When user selects a direct share item from ShareSheet, the app will receive a share intent which includes the ID of the corresponding shortcut in the extras field.

Value: "android.intent.extra.shortcut.ID"

FLAG_MATCH_CACHED

static val FLAG_MATCH_CACHED: Int

Include cached shortcuts in the result.

Value: 1 << 3

See Also

FLAG_MATCH_DYNAMIC

static val FLAG_MATCH_DYNAMIC: Int

Include dynamic shortcuts in the result.

Value: 1 << 1

See Also

FLAG_MATCH_MANIFEST

static val FLAG_MATCH_MANIFEST: Int

Include manifest shortcuts in the result.

Value: 1 << 0

See Also

FLAG_MATCH_PINNED

static val FLAG_MATCH_PINNED: Int

Include pinned shortcuts in the result.

Value: 1 << 2

See Also

Public methods

addDynamicShortcuts

open static fun addDynamicShortcuts(
    @NonNull context: Context,
    @NonNull shortcutInfoList: MutableList<ShortcutInfoCompat!>
): Boolean

Publish the list of dynamic shortcuts. If there are already dynamic or pinned shortcuts with the same IDs, each mutable shortcut is updated.

This API will be rate-limited.

Return
Boolean true if the call has succeeded. false if the call fails or is rate-limited.
Exceptions
IllegalArgumentException if getMaxShortcutCountPerActivity(Context) is exceeded, or when trying to update immutable shortcuts.

createShortcutResultIntent

@NonNull open static fun createShortcutResultIntent(
    @NonNull context: Context,
    @NonNull shortcut: ShortcutInfoCompat
): Intent

Returns an Intent which can be used by the launcher to pin shortcut.

This should be used by an Activity to set result in response to Intent#ACTION_CREATE_SHORTCUT.

Parameters
shortcut ShortcutInfoCompat: new shortcut to pin
Return
Intent the intent that should be set as the result for the calling activity

disableShortcuts

open static fun disableShortcuts(
    @NonNull context: Context,
    @NonNull shortcutIds: MutableList<String!>,
    @Nullable disabledMessage: CharSequence?
): Unit

Disable pinned shortcuts, showing the user a custom error message when they try to select the disabled shortcuts. For more details, read Disable shortcuts. Compatibility behavior:

  • API 25 and above, this method matches platform behavior.
  • API 24 and earlier, this method behalves the same as removeDynamicShortcuts

Exceptions
IllegalArgumentException If trying to disable immutable shortcuts.
IllegalStateException when the user is locked.

enableShortcuts

open static fun enableShortcuts(
    @NonNull