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.

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 MutableList<ShortcutInfoCompat!>
getDynamicShortcuts(@NonNull context: Context)

Return all dynamic shortcuts from the caller app.

open static Int

open static Boolean

open static Unit

Delete all dynamic shortcuts from the caller app.

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

Delete dynamic shortcuts by ID.

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

Request to create a pinned shortcut.

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"

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 Context: new shortcut to pin
Return
Intent: the intent that should be set as the result for the calling activity

getDynamicShortcuts

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

Return all dynamic shortcuts from the caller app.

This API is intended to be used for examining what shortcuts are currently published. Re-publishing returned ShortcutInfos via APIs such as addDynamicShortcuts(Context, List) may cause loss of information such as icons.

getMaxShortcutCountPerActivity

open static fun getMaxShortcutCountPerActivity(@NonNull context: Context): Int
Return
Int: The maximum number of static and dynamic shortcuts that each launcher icon can have at a time.

isRequestPinShortcutSupported

open static fun isRequestPinShortcutSupported(@NonNull context: Context): Boolean
Return
Boolean: true if the launcher supports requestPinShortcut, false otherwise

removeAllDynamicShortcuts

open static fun removeAllDynamicShortcuts(@NonNull context: Context): Unit

Delete all dynamic shortcuts from the caller app.

removeDynamicShortcuts

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

Delete dynamic shortcuts by ID.

requestPinShortcut

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

Request to create a pinned shortcut.

On API <= 25 it creates a legacy shortcut with the provided icon, label and intent. For newer APIs it will create a android.content.pm.ShortcutInfo object which can be updated by the app.

Use android.app.PendingIntent#getIntentSender() to create a IntentSender.

Parameters
shortcut Context: new shortcut to pin
callback Context: if not null, this intent will be sent when the shortcut is pinned
Return
Boolean: true if the launcher supports this feature

updateShortcuts

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

Update all existing shortcuts with the same IDs. Target shortcuts may be pinned and/or dynamic, but they must not be immutable.

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 trying to update immutable shortcuts.