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?
-
Doesn't Android add a shortcut to an application automatically by default upon installation? – Geeky Guy Aug 20 '13 at 04:53
-
2@Renan - A shortcut is added to the app list, but not to the home screen. – Ted Hopp Aug 20 '13 at 04:56
-
1yeah. the app launcher is added to apps list but not on homescreen. but apps downloaded from play-store generally create their shortcuts on homescreen. – S P Aug 20 '13 at 05:01
6 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
-
1from where to trigger this ? I want to create shortcut EVEN BEFORE I START MY APP , i.e. as soon as I install it. – S P Aug 20 '13 at 05:05
-
3You can either create it by your own app or create it by other running app. There is no other ways. PlayStore is able to do that because it installed your app. Think of this way: if there is already an app of yours running on the device, and it is listening for the apk installed broadcast event, then it could perform this add shortcut action for you. But this won't be the normal case, you cannot expect you have such facility on every device. – Robin Aug 20 '13 at 05:08
-
-
I am trying to achieve same thing, and this code appears to do nothing for me. What could be the cause? – yahya Nov 11 '13 at 11:41
-
7Ok, found it. This requires "com.android.launcher.permission.INSTALL_SHORTCUT" permission. – yahya Nov 11 '13 at 12:11
-
-
2
-
3After you create shortcut, the next time it gives us the message `Shortcut "AppName" already exists`. How can I Hide this toast message? – Bob Sep 15 '14 at 05:28
-
1
-
1
-
Is there a way to install the shortcut from a gradle script? (meaning from Android Studio) – CodyF Jan 12 '17 at 15:18
-
works like charm, but it can be annoying to user, since it creates icon again if user deletes it. we can definitely refine this method even more. Anyways thanks. – Amir Dora. May 08 '18 at 20:13
-
1
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#!

- 4,837
- 2
- 32
- 37
-
I didnt forget that. But this wont force the app to create the shortcut upon installation :P – S P May 15 '14 at 03:42
-
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.
-
12Thanks for your help. But I find some applications, which I install from play store, they automatically create their shortcuts. – S P Aug 20 '13 at 05:00
-
2I get that too in all of my devices. Just bought a new phone, redownloaded everything from Google Play... Icons only stopped appearing in my screens when there was no more space for them. – Geeky Guy Aug 20 '13 at 05:02
-
8
-
1but if play store apps are creating shortcuts, i think its somehow doable. :P :( – S P Aug 20 '13 at 05:03
-
5@SP - It's the play store (in cooperation with the launcher), not your app, that's doing that. If you turn the option off in the store, then the shortcuts won't be installed on the home screen (at least not at install time). When the app runs, that's a different story, as Robin points out. – Ted Hopp Aug 20 '13 at 05:14
-
If you install your application, neither your application, nor any services or other processes are active! Android want's the user to make the first step in "opening" the application. You are not able to install a shortcut directly! Thats the answer. Notice: On most devices the launcher will create a shortcut for your application itself.
Can you install shortcuts in runtime after the user has somehow started your app at least once? : yes (see Robins answer).
Is there a workaround? Maybe, but no good one.
Update, Another hint: If you have already an application on the device of the user. (For example if your second app that gets installed is the key for "going pro" or something), then you actually can start the second application from the first one, without the user has started the second app ever (and add a shortcut).

- 3,336
- 24
- 55
-
@downvoter, please add a comment if you downvote someones answer. Otherwise a downvote is useless. My answer is the only totally correct one in context of the question. – JacksOnF1re Aug 08 '17 at 13:32
Create function to call intent of shortcut:
private void criarAtalho() { Intent shortcutIntent = new Intent(getApplicationContext(), SplashScreen.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "nomeDaApp"); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate getApplicationContext().sendBroadcast(addIntent); }
write on OnCreat the call of function:
if(!getSharedPreferences("APP_PREFERENCE", Activity.MODE_PRIVATE).getBoolean("IS_ICON_CREATED", false)){ criarAtalho(); getSharedPreferences("APP_PREFERENCE", Activity.MODE_PRIVATE).edit().putBoolean("IS_ICON_CREATED", true).commit(); }
set the permissions on manifest:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

- 107,652
- 25
- 181
- 264

- 63
- 4
First, add permission for adding shortcut to manifest:
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Then, call the function below.
public void createShortcut(){
Intent intentShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intentShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
Parcelable appicon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
intentShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, appicon);
intentShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), MainActivity.class));
intentShortcut.putExtra("duplicate", false);
sendBroadcast(intentShortcut);
}

- 3,883
- 3
- 29
- 41

- 81
- 2
- 8
-
it's working, but each time app is launched app icon is created. Sharedpref can be used to prevent that, you can add that to your answer as well. :) anyways thanks – Amir Dora. May 08 '18 at 20:12