How to enable automatic shortcut creation after app downloads and installs from Android Market?

Viewed 22501

I notice that some apps on the Android Market automatically create shortcuts on the desktop after downloading and installing onto your device, while some don't. How would I go about implementing this behavior?

4 Answers

I've tested this demo. And put the addShortcut() in the onCreate(). Then deploy from intelliJ, my GEL(Google Experience Launcher) do create shortcut for the first launch. I afraid it keep creating shortcut, but it seem won't create another shortcut if app launch next time. Try for yourself if you needed.

private void addShortcut() {
    //Adding shortcut for MainActivity
    //on Home screen
    Intent shortcutIntent = new Intent(getApplicationContext(),
            MainActivity.class);

    shortcutIntent.setAction(Intent.ACTION_MAIN);

    Intent addIntent = new Intent();
    addIntent
            .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                    R.drawable.ic_launcher));

    addIntent
            .setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
}
Related