O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

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 context: Context,
    @NonNull shortcutInfoList: MutableList<ShortcutInfoCompat!>
): Unit

Re-enable pinned shortcuts that were previously disabled. If the target shortcuts are already enabled, this method does nothing. Compatibility behavior:

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

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

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.

getIconMaxHeight

open static fun getIconMaxHeight(@NonNull context: Context): Int

Return the max height for icons, in pixels.

getIconMaxWidth

open static fun getIconMaxWidth(@NonNull context: Context): Int

Return the max width for icons, in pixels.

Note that this method returns max width of icon's visible part. Hence, it does not take into account the inset introduced by android.graphics.drawable.AdaptiveIconDrawable. To calculate bitmap image to function as android.graphics.drawable.AdaptiveIconDrawable, multiply 1 + 2 * android.graphics.drawable.AdaptiveIconDrawable#getExtraInsetFraction() to the returned size.

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.

getShortcuts

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

Returns ShortcutInfoCompats that match matchFlags.

Parameters
matchFlags Int: result includes shortcuts matching this flags. Any combination of: Compatibility behavior:
  • API 30 and above, this method matches platform behavior.
  • API 25 through 29, this method aggregates the result from corresponding platform api.
  • API 24 and earlier, this method can only returns dynamic shortcut. Calling this method with other flag will be ignored.
Return
MutableList<ShortcutInfoCompat!> list of ShortcutInfoCompats that match the flag.

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

Exceptions
IllegalStateException when the user is locked.

isRateLimitingActive

open static fun isRateLimitingActive(@NonNull context: Context): Boolean

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

For details, see Rate limiting.

Exceptions
IllegalStateException when the user is locked.

isRequestPinShortcutSupported

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

pushDynamicShortcut

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

Publish a single dynamic shortcut. If there are already dynamic or pinned shortcuts with the same ID, each mutable shortcut is updated.

This method is useful when posting notifications which are tagged with shortcut IDs; In order to make sure shortcuts exist and are up-to-date, without the need to explicitly handle the shortcut count limit.

Return
Boolean true if the call has succeeded. false if the call fails or is rate-limited.
Exceptions
IllegalArgumentException if trying to update an immutable shortcut.
IllegalStateException when the user is locked.

removeAllDynamicShortcuts

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

Delete all dynamic shortcuts from the caller app.

removeDynamicShortcuts

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

Delete dynamic shortcuts by ID.

removeLongLivedShortcuts

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

Delete long lived shortcuts by ID. Compatibility behavior:

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

Exceptions
IllegalStateException when the user is locked.

reportShortcutUsed

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

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. For more details, read about tracking shortcut usage.

The information is accessible via android.app.usage.UsageStatsManager#queryEvents Typically, launcher apps use this information to build a prediction model so that they can promote the shortcuts that are likely to be used at the moment.

Exceptions
IllegalStateException when the user is locked.

This method is not supported on devices running SDK < 25 since the platform class will not be available.

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 ShortcutInfoCompat: new shortcut to pin
callback IntentSender?: if not null, this intent will be sent when the shortcut is pinned
Return
Boolean true if the launcher supports this feature

setDynamicShortcuts

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

Publish the list of shortcuts. All existing dynamic shortcuts from the caller app will be replaced. If there are already pinned shortcuts with the same IDs, the mutable pinned shortcuts are updated.

This API will be rate-limited. Compatibility behavior:

Return
Boolean true if the call has succeeded. false if the call is rate-limited.
Exceptions
IllegalArgumentException if getMaxShortcutCountPerActivity is exceeded, or when trying to update immutable shortcuts.
IllegalStateException when the user is locked.

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.