From Android Wiki
|Line 16:||Line 16:|
Latest revision as of 08:48, 31 January 2013
A “shortcut” is, in one sense, any tappable icon that the Launcher lets you put on a home screen. Each such icon is nothing more than a container for an Intent, which is sent when you tap the icon.
The Launcher populates the contents of its app tray based on the declared intent-filters in the manifests of all installed packages; every exported activity with an intent-filter saying they will accept an intent with action “android.intent.action.MAIN” and category “android.intent.category.LAUNCHER” will have its icon appear in the app tray. From here you can launch any of these icons directly, or long-tap them to drag copies to a home screen.
But apps can tell the Launcher to create shortcuts containing any intent at all. When you long-tap in an empty area of a home screen, you get an “Add to Home” display letting you select from apps (again) but also a special category called “shortcut”. This section lists activities that specify intent-filters indicating that they will accept an intent with action “android.intent.action.CREATE_SHORTCUT” and category “android.intent.category.DEFAULT”; when you select an item in this list, such an intent is sent to that activity.
How the activity responds to this intent is up to it, but the convention is that it offers a UI giving the user options for the shortcut(s) to create. When the user confirms these options, the activity should send an intent with action “com.android.launcher.action.INSTALL_SHORTCUT” (and no category), which contains the actual intent that the Launcher will save with the created shortcut, to be sent when the user taps it.
You can also remove shortcuts (any shortcuts, not just your own?) with the “com.android.launcher.action.UNINSTALL_SHORTCUT” intent.
Note the app package will need the permission “com.android.launcher.permission.INSTALL_SHORTCUT” to send the INSTALL_SHORTCUT intent, and “com.android.launcher.action.UNINSTALL_SHORTCUT” to send the UNINSTALL_SHORTCUT intent. Neither are documented in the official list.