How can I add my application's shortcut to the homescreen upon app installation?

S P picture S P · Aug 20, 2013 · Viewed 72.7k times · Source

I want to create my app's shortcut/launcher icon on the homescreen as soon as I install my app (even before I start it). Is that possible? How might I do that?

Answer

Robin picture Robin · Aug 20, 2013

Since ICS, you can do like this:

public void createShortCut(){
    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutintent.putExtra("duplicate", false);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcutname));
    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), EnterActivity.class));
    sendBroadcast(shortcutintent);
}

Please also refer to the source code of launcher at: this link

Edit : If somebody would miss reading comment so adding following line.

This requires "com.android.launcher.permission.INSTALL_SHORTCUT" permission