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

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


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


You forgot to add permissions:

 <uses-permission        android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />    <uses-permission        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

Great tutorial here:http://androidforbegineers.blogspot.in/2014/01/android-home-screen-shortcut.html#!


NOTE: This answer is now wrong. See, for instance, Robin's answer for a way to do this.


As far as I know, an app cannot force itself onto the home screen. It gets added to the app list that the launcher app maintains, but the home screen is generally under user control. Giving apps the ability to clutter up the home screen would be an open invitation for abuse.