Static Shortcuts in Android

Shobhith J B
3 min readJun 9, 2023

--

Hey People. In this article I am going to describe about static shortcuts and steps to create them.

Let’s goo………….!

If you want to know the basics of shortcuts read this article,

Static shortcuts are consistent shortcuts which are created and published once, when the launcher activity is opened. Static shortcuts are defined inside a resource file (xml) file.

These are called static shortcuts because once the static shortcuts are created, it cannot be changed over the lifetime of your app’s current version.

In simple words, Static shortcuts can only be changed/modified when the new version of the app is updated to the play-store. Because static shortcuts are defined inside xml file, and to change/modify shortcuts as a developer we need to change that particular xml file. And users can see the changes only after we update the app to newer version.

Good Examples of static shortcuts include Viewing sent messages in Messaging app, Setting an alarm in Clock App, Take Photo in Camera App.

How to Create Static Shortcuts ? 🤔

There are few steps that you need to follow to create static shortcuts.

Step1:

You need to find launcher activity whose intent filters are set to android.intent.action.MAIN action and the android.intent.category.LAUNCHER category inside app’s manifest file (AndroidManifest.xml).

Step2:

Add <meta-data> element to launcher activity.

You will get error at this line android:resource=@xml/shortcuts. Don’t worry we will fix this in the next step.

Here(android:resource=@xml/shortcuts) the filename shortcuts can be anything but it has to match with the name you are going to give in the next step.

Step3:

Create a new resource file res/xml/shortcuts.xml.

If you don’t know how to create file. On Android View go to res/xml folder, right click on it. Select New -> Xml Resource File. Give filename as shortcuts and press OK.

Step 4:

In the newly created shortcuts.xml, add a <shortcuts> root element, which contains multiple <shortcut> elements. Each <shortcut> element is used to create a new shortcut which contains information like its icon, its description labels, and the intents that it launches when we click on particular shortcut.

Here I will create shortcut for writing new messages.

For every shortcut android:shortcutId and android:shortcutShortLabel is mandatory and rest of the properties are optional.

First Let’s look at the output:

Now Let’s see each of the attribute in detail:

android: shortcutId: A string literal, which is used to identify particular shortcut. And you can’t set this attribute’s value to a resource string, such as @string/id.

android:shortcutShortLabel: A short text which describes what the shortcut does. This attribute’s value must be a resource string, such as @string/short_label.

android:shortcutLongLabel: A long text which describes what the shortcut does. If there’s enough space, the launcher displays this value instead of android:shortcutShortLabel. This attribute’s value must be a resource string, such as @string/long_label. This is optional.

android:shortcutDisabledMessage: The message which appears when user attempts to launch a disabled shortcut. Static shortcuts can be disabled by setting android:enabled attribute to false. This attribute’s value must be a resource string, such as @string/disabled_label. This is optional.

android:icon: The icon which is displayed to the user for a particular shortcut when users long click on app. This is optional.

<intent> :tThe action that the system performs when the user clicks on the shortcut. The intent includes android:action, android:targetPackage, android:targetClass. This is optional.

<categories> : Provides a grouping for the types of actions that your app’s shortcuts perform. This is optional.

<capability-binding> : Capability binding enables users to use spoken commands with Google Assistant to invoke this shortcut whenever we use built in intents. This is optional.

Yup….That’s it for this article. Thank you for reading. Until Next Time. Happy Coding 😉

Photo by Fab Lentz on Unsplash

--

--

Shobhith J B

Native Android Developer | Kotlin | Java | Travel Enthusiast