Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 268
wikichen Avatar asked Jul 19 '11 22:07

wikichen


People also ask

How do I turn off auto Create shortcut on Android?

On the Play Store settings, search for the option Auto-add widgets. If the option is checked and enabled, shortcut of every new app will be added to your home screen after they are installed, as long as there's space for it. To disable the feature simple uncheck the option and press the back soft key. That's all.


2 Answers

Send an intent to the Launcher. Broadcast a INSTALL_SHORTCUT intent with a EXTRA_SHORTCUT_NAME and EXTRA_SHORTCUT_INTENT. The extra EXTRA_SHORTCUT_DUPLICATE can be used to help manage duplicate shortcuts being made. The details can be found in the Launcher2 project in the AOSP repository.

Please be careful with this, some users may not appreciate having a shortcut created without permission.

Here is some pseudo code:

Intent installIntent = new Intent(InstallShortcutReceiver.ACTION_CREATE_SHORTCUT);
Intent myAppIntent = new Intent(Context.getPackageContext(), MyActivity.class);
installIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Context.getString(R.string.app_name));
installIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myAppIntent);
installIntent.putExtra(Intent.SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
Context.sendBroadcast(installIntent);

There is some more information in the Intent class as well as an alternate Intent action.

like image 122
Dan S Avatar answered Sep 21 '22 15:09

Dan S


It turns out the Android Market automatically installs a desktop shortcut when you download an app. I'm noticing this default behavior on an Android 3.1 tablet with a Honeycomb (3.0+) targeted app. It seems like this isn't standard convention for apps running on previous Android versions, where explicit user input/permission is needed upon first downloading/launching the app.

like image 34
wikichen Avatar answered Sep 17 '22 15:09

wikichen