Skip to content

Instantly share code, notes, and snippets.

@donrokzon
Created March 28, 2018 10:16
Show Gist options
  • Select an option

  • Save donrokzon/3299a0e71f2e4d445bfe93208b729427 to your computer and use it in GitHub Desktop.

Select an option

Save donrokzon/3299a0e71f2e4d445bfe93208b729427 to your computer and use it in GitHub Desktop.
Add shortcuts api below Nougat
Intent shortcut = new Intent(getActivity(), MainActivity.class);
shortcut.setAction(Intent.ACTION_MAIN);
Intent add = new Intent();
add.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
add.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Your Activity Name");
add.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.ic_clock));
add.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getActivity().sendBroadcast(add);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment