

App Shortcut on Android devices
Recently Google has brought update to their latest Android system Nougat with the version 7.1 (API 25). It is a major release for Android developers to bundle multiple items under the hood with interesting functionalities. It will simplify user’s experience with a latest feature called “App Shortcuts”.
This post explores what is an App Shortcut and how you can use it with a small example..
What is an App Shortcut?
- Static App Shortcuts: They are defined the resource file of an app’s APK and remain constant throughout the application.Static shortcuts are immutable which means that you must wait until you update your entire app to change the details of these static shortcuts.
Why use Static App shortcut:
Static shortcuts are used for generic actions of the app that remains persistent until you update your app.
- Dynamic App Shortcuts: Dynamic shortcuts are created at runtime of your app. You can publish, update, and remove these shortcuts as you use these applications. It uses ShortcutManager API.
Why use Dynamic App shortcut:
Dynamic shortcuts are used to provide specific actions within your app that could be changed based on user’s interaction within the app.
Implementing App Shortcuts
Static Shortcuts
To create a static shortcut,
1. Add a meta-data tag to your launcher Activity in the manifest and provide the shortcuts resource file.
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
2. Create a new resource file: res/xml/shortcuts.xml.
3. This is where we will specify all shortcuts that your app can support.
4. Each element contains information about a static shortcut, including its icon, its description labels, and the intents that it launches within the app.
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <shortcut android:icon="@drawable/add_event" android:shortcutId="shortcut_add_events" android:shortcutLongLabel="@string/app_shortcut_longLabel_view_events" android:shortcutShortLabel="@string/app_shortcut_shortLabel_view_events" > <intent android:action="android.intent.action.VIEW" android:targetClass="com.knowarth.appshortcutdemo.AddEvents" android:targetPackage="com.knowarth.appshortcutdemo" ></intent> </shortcut> </shortcuts>
These are very easy steps to implement. However, you may notice that as you press the Back button on your phone, you will be taken to the Home Screen.
Now, if you want to to navigate it within your app then we can add multiple intent tags under the shortcut once we previously created.
<shortcut android:icon="@drawable/add_event" android:shortcutId="shortcut_add_events" android:shortcutLongLabel="@string/app_shortcut_longLabel_view_events" android:shortcutShortLabel="@string/app_shortcut_shortLabel_view_events" > <intent android:action="android.intent.action.MAIN" android:targetPackage="com.knowarth.appshortcutdemo" android:targetClass="com.knowarth.appshortcutdemo.MainActivity"></intent> <intent android:action="android.intent.action.VIEW" android:targetClass="com.knowarth.appshortcutdemo.AddEvents" android:targetPackage="com.knowarth.appshortcutdemo" ></intent> </shortcut>
Once you have followed above steps, your phone’s screen will look like an image shown below.

Dynamic Shortcuts
To create dynamic shortcut, you need to use ShortcutManager APK. You will need to define each shortcut using ‘Shortcutinfo’ that provides UI information of the shortcut to your phone.
You can also use multiple intent tags to navigate within the application. Follow these steps to create a Dynamic App Shortcut using MainActivity.onCreate() method.
Change your shortcut preference
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_view_events") .setShortLabel("View Events") .setLongLabel("View Events") .setRank(1) .setIcon(Icon.createWithResource(this, R.drawable.view_event)) .setIntents(new Intent[]{ new Intent(Intent.ACTION_VIEW, Uri.EMPTY, this, MainActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), new Intent(Intent.ACTION_VIEW, Uri.EMPTY, this, ViewEvents.class) }) .build(); shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut ));

Given are brief examples on how to create an application shortcut with your android phone on Android Nougat.
Related Blogs




Categories
Related Case Studies





Services
Solutions
Products

Tell us your idea
We like fast - the same way the technology market moves. In the time it takes you to say"I'hv got a great idea", someone else has already started working on a similar project half the world away.