I recently stumbled on a feature when using an Android 9 Pie device, it is called App Shortcuts. With app shortcuts, specific actions are defined in-app to reduce users’ trips before a specific action can be performed. Good UX is poised with the task of reducing the number of clicks before users can access useful features in the app.
With shortcuts, important features of your app can be made accessible easily. An example is the Skype messaging app shortcut in the image below. The main features of Skype are well spelt out for ease of accessibility.
I have provided a simple app to illustrate this concept.
It is safe to note that this feature is only available on devices that are running Android 7.0 Nougat and newer versions of Android, that is API 25 and higher.
There are three different scenarios in which app shortcuts may be provided in your app. It can be one of Static shortcuts, dynamic shortcuts, or pinned shortcuts. It can be a combination of more than one of these three.
Static shortcuts are used to link contents of the app that are consistent and important. They link units in the app that will not change throughout the app.
Dynamic shortcuts are used for context-sensitive actions within the app. This type of shortcut will require constant or frequent updates.
Pinned shortcuts are user-driven; that is, the user determines which unit of the app is important and needs to be easier to access.
This tutorial contains guide to creating static shortcuts. Dynamic and pinned shortcuts are treated in another post.
Most launchers can only display four shortcuts
These shortcuts are developer-specified and are defined in a resource file that is packaged into an APK or app bundles.
We’ll create a new Android app project on Android studio
I have created three activities that will be used in this tutorial, as shown in the image below.
MainActivity class is the launcher for this sample app, and it contains the
MAIN intent filter. The other activities provided in this sample code does not contain specific links to open them. We will be using app shortcuts to open these screen.
This is how the AndroidManifest.xml file looks like before adding shortcuts.
This is the AndroidManifest.xml file after adding shortcuts. The main difference is the addition of the meta-data tag which includes a reference to the shortcut resource.
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
The next step is to create the
shortcuts file in
shortcuts.xml file, the root element will be
<shortcuts> that can host one of more
<shortcut> elements. Each of the elements in the
<shortcut> tag contain enough information that defines our shortcut. The full
shortcuts.xml file is shown below.
It is important to note that the
<intent/>section of a
<shortcut/>tag contains the exact Activity to open when the shortcut is clicked.
The output of this tutorial is shared in the video below.
Are you able to replicate these steps and you got good results? Please share your experience in the comment section.
If you have any questions regarding any of these steps or general android questions, do not hesitate to ask in the comment section.
Full project URL on Github: