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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With