ShortcutManager.RequestPinShortcut(ShortcutInfo, IntentSender) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Request to create a pinned shortcut.
[Android.Runtime.Register("requestPinShortcut", "(Landroid/content/pm/ShortcutInfo;Landroid/content/IntentSender;)Z", "GetRequestPinShortcut_Landroid_content_pm_ShortcutInfo_Landroid_content_IntentSender_Handler", ApiSince=26)]
public virtual bool RequestPinShortcut (Android.Content.PM.ShortcutInfo shortcut, Android.Content.IntentSender? resultIntent);
[<Android.Runtime.Register("requestPinShortcut", "(Landroid/content/pm/ShortcutInfo;Landroid/content/IntentSender;)Z", "GetRequestPinShortcut_Landroid_content_pm_ShortcutInfo_Landroid_content_IntentSender_Handler", ApiSince=26)>]
abstract member RequestPinShortcut : Android.Content.PM.ShortcutInfo * Android.Content.IntentSender -> bool
override this.RequestPinShortcut : Android.Content.PM.ShortcutInfo * Android.Content.IntentSender -> bool
Parameters
- shortcut
- ShortcutInfo
Shortcut to pin. If an app wants to pin an existing (either static or dynamic) shortcut, then it only needs to have an ID. Although other fields don't have to be set, the target shortcut must be enabled.
<p>If it's a new shortcut, all the mandatory fields, such as a short label, must be
set.
- resultIntent
- IntentSender
If not null, this intent will be sent when the shortcut is pinned.
Use android.app.PendingIntent#getIntentSender()
to create an IntentSender
.
To avoid background execution limits, use an unexported, manifest-declared receiver.
For more details, see
Creating pinned shortcuts.
Returns
TRUE
if the launcher supports this feature. Note the API will return without
waiting for the user to respond, so getting TRUE
from this API does not mean
the shortcut was pinned successfully. FALSE
if the launcher doesn't support this
feature.
- Attributes
Remarks
Request to create a pinned shortcut. The default launcher will receive this request and ask the user for approval. If the user approves it, the shortcut will be created, and resultIntent
will be sent. If a request is denied by the user, however, no response will be sent to the caller.
Only apps with a foreground activity or a foreground service can call this method. Otherwise, it'll throw IllegalStateException
.
It's up to the launcher to decide how to handle previous pending requests when the same package calls this API multiple times in a row. One possible strategy is to ignore any previous requests.
<b>Note:</b> See also the support library counterpart androidx.core.content.pm.ShortcutManagerCompat#requestPinShortcut( Context, ShortcutInfoCompat, IntentSender)
, which supports Android versions lower than VERSION_CODES#O
using the legacy private intent com.android.launcher.action.INSTALL_SHORTCUT
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.