Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 497
S P Avatar asked Aug 20 '13 04:08

S P


People also ask

Why are my apps not showing up on my home screen Android?

This is because if the app hasn't been installed yet, it will not appear on the home screen. You can find the installed and uninstalled apps in App Gallery, where the pre-installed apps and the third-party ones are all be stored.


1 Answers

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

like image 72
Robin Avatar answered Oct 12 '22 23:10

Robin