Hello,
But neither seem to produce any result.
You added the permission is right, but you need to specific android platform code to add the short icon as well. Firstly, If I want to add short cut when I click the button event. You need to use Conditional compilation to wrap the android specific code.
For Android, you can add short icon by AndroidX.Core.Content.PM.ShortcutManagerCompat
You can refer to the following code.
private void OnCounterClicked(object sender, EventArgs e)
{
#if ANDROID
//on Home screen
if (AndroidX.Core.Content.PM.ShortcutManagerCompat.IsRequestPinShortcutSupported(Platform.AppContext))
{
AndroidX.Core.Content.PM.ShortcutInfoCompat shortcutInfo = new AndroidX.Core.Content.PM.ShortcutInfoCompat.Builder(Platform.AppContext, "#1")
.SetIntent(new Android.Content.Intent(Platform.AppContext, typeof(MainActivity)).SetAction(Android.Content.Intent.ActionMain)) // !!! intent's action must be set on oreo
.SetShortLabel("Test")
.SetIcon(AndroidX.Core.Graphics.Drawable.IconCompat.CreateWithResource(Platform.AppContext, Resource.Mipmap.appicon))
.Build();
AndroidX.Core.Content.PM.ShortcutManagerCompat.RequestPinShortcut(Platform.AppContext, shortcutInfo, null);
}
else
{
// Shortcut is not supported by your launcher
}
#endif
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.