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
Starting from Android O, this is the way to create a shortcut:
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
.setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
.setShortLabel(label)
.setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_MAIN))
.build();
shortcutManager.requestPinShortcut(pinShortcutInfo, null);
}
It has a lot of limitations, sadly:
For pre-Android O, you can use ShortcutManagerCompat to create new shortcuts too, without any of those limitations.