What I want to do is:
1) I\'m inside an activity, there are 2 buttons. If I click the first one a shortcut is created in my home screen. The shortcut open an
public static void addShortcutToHomeScreen(Context context)
{
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context))
{
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, "#1")
.setIntent(new Intent(context, YourActivity.class).setAction(Intent.ACTION_MAIN)) // !!! intent's action must be set on oreo
.setShortLabel("Test")
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_launcher))
.build();
ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null);
}
else
{
// Shortcut is not supported by your launcher
}
}
I've used it, but some devices on the home screen adds 2 icons. I did not understand??