Implementing Static App Shortcuts in Android

M Farhan Majid
Bobobox Engineering
3 min readJul 28, 2022

--

Hello again!

We have talked about several things that could enhance users’ experience in your Android application.

Let’s add another cool thing to the list: App Shortcut.

What is an App Shortcut? 🤔

As the name suggests, an App Shortcut is a shortcut that performs a certain action in your app.

Take the Google Calendar app below for an example. When you long-press the app’s icon launcher, a popup will shows three shortcuts that can be used to create new task, reminder, or event.

This simple yet powerful feature is a good way to decrease the number of actions that users need to perform in order to do something!

There are 3 different types of App Shortcuts available: static shortcuts, dynamic shortcuts, and pinned shortcuts (you can read the differences here). However, in this article, we are only going to implement the simplest one first: static shortcuts.

Simply put, Static App Shortcuts are App Shortcuts that are defined in an XML file and can’t be changed without rolling out a new version of the app. These types of shortcuts are typically used for common use cases, such as composing a new email (Gmail) or creating a new event (Google Calendar).

How to Implement Static App Shortcuts?

Here are the steps needed to implement static app shortcuts in your app.

1. The first thing you need to do is create a file named shortcuts.xml in your res/xml folder. This is where you’re going to register your Static App Shortcuts.
In this series, we are using the Bobobox app as our use case app. Here, we are adding a shortcut to book a Cabin:

The important thing to notice here is the usage of <shortcut> element as the representation of a Static App Shortcut. You have to specify its shortcutId and shortcutShortLabel attributes. You also need to add one or more <intent> element(s) inside your <shortcut> element. These intents will be called in order of their appearance when a shortcut is activated. So, in this case, the shortcut will call MainActivity and then CabinActivity.

2. And lastly, add a new <meta-data> element inside of your Activity whose intent filters are set to android.intent.action.MAIN action and android.intent.category.LAUNCHERcategory. Typically this is your MainActivity.
Add the new element like this inside your AndroidManifest.xml file:

3. And, that’s how you implement Static App Shortcuts! Pretty easy, right? 😀

Normally, you can add up to 4 shortcuts for your app. When you have added your shortcuts to your app, you can test them by running your app and long-pressing the app’s launcher icon like this:

Static App Shortcut in action! By long-pressing an app’s icon launcher, you can choose which action you want to perform. (Disclaimer: This is just a demonstration for this article and might not be representative of the real Bobobox app).

Do you Like this Article?

Leave us some claps 👏 and follow our Medium publication for more articles like this.

And don’t forget to download our app on your Android or iOS and book your first room in Bobobox! 😀

--

--