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
To add a shortcut to the home screen use this code.
public void addShortcutToHomeScreen(Context context) {
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, "#1")
.setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_MAIN)) // !!! intent's action must be set on oreo
.setShortLabel("Label Goes Here")
.setIcon(IconCompat.createWithResource(context, R.mipmap.ic_launcher_shortcut))
.build();
ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null);
} else {
Toast.makeText(context, R.string.no_shortcut, Toast.LENGTH_SHORT).show();
}
}
and no extra permission need !!!