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?
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.
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.
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.
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