Now, app icons have power to teleport!! No kidding.

Previously, the sole purpose of the app icons was to launch the app. But now, app icons are intelligent, they can take you to your favourite section directly in your app without going through the old and tedious linear flow.

Consider you are using a messenger app, and you want to chat with the person you frequently talk with. Traditionally, you would open the app and search for your contact and open the chat with him/her. But with app shortcuts, you can directly go to that contact without even launching the app.

Most popular apps like Twitter and Google Play Music are already using app shortcuts.

Are you familiar with Quick Actions of iOS?

Apple introduced 3D Touch in iOS 10 with the launch of iPhone 6S. Quick Actions is one of the features of 3D Touch in iOS. Quick Actions are shown with a popup when you hold your app icon.

 

Quick Actions in iPhone
Quick Actions in iPhone

How App Shortcuts work in Android?

With the release of Android Nougat 7.1, App Shortcuts feature for Android was introduced. App Shortcuts is similar feature to iOS Quick Actions. App Shortcuts is one of the most useful Android Nougat Features which gives power to app icon.

App Shortcuts in Android
App Shortcuts in Android

 

App Shortcuts popup when you hold an app icon which supports this feature. You can select any shortcut to open that app feature directly.

Why you should have App Shortcuts in your App?

App Shortcuts best fit your app when your app has features which are frequently used by the users. It allows users to directly access important feature without pushing user to start from splash screen.

If you are developing a Chat Application, you can add app shortcuts such as new message directly to a contact and add new contact.

If you are developing an E-Commerce Application, you can add app shortcuts such as Quick Search, Go to Cart, Offers List, Favourites, etc.
If you are developing any social networking app, you can add app shortcuts such as Add New Post, Add Stories and Notifications.

Watch App Shortcuts Teleporting You

Navigating to New Message with App Shortcuts
Navigating to New Message without App Shortcuts
Navigating to New Message without App Shortcuts
Navigating to New Message with App Shortcuts

 
As you can see in the first image, to write a new message in twitter, a user has to open the app, go to messages section and tap on New Message Button.

With app shortcuts, as you can see in second image, user just holds icons and selects New Message, and user gets teleported to New Message screen directly.

How to integrate App Shortcuts in Android App Development?

Each shortcut of your references the intents, which launch a specific action in your app when users select the shortcut.

Before implementing App shortcuts, please note that only activities that handle the Intent.ACTION_MAIN action and the Intent.CATEGORY_LAUNCHER category—can have shortcuts.

There are 3 types of App Shortcuts:

  1. Static shortcuts: They are defined in a resource file that is packaged into an APK or app bundle. Static shortcuts cannot be changed without updating your app.
  2. Dynamic shortcuts: They can be published, updated, and removed by your app only at runtime.
  3. Pinned shortcuts: They can be added to supported launchers at runtime, if the user grants permission.

Create Static Shortcuts

To create a static shortcut, you can follow the steps given below:

<meta-data android:name=”android.app.shortcuts”
           android:resource=“@xml/shortcuts” />
  1. In your app’s manifest file (AndroidManifest.xml), find an activity whose intent filters are set to the android.intent.action.MAIN action and the android.intent.category.LAUNCHER category.
  2. Add a <meta-data> element to this activity that references the resource file where the app’s shortcuts are defined:
  3. Create a new resource file: res/xml/shortcuts.xml.
  4. In this new resource file, add a <shortcuts> root element, which contains a list of <shortcut> elements. Each <shortcut> 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:shortcutId=“newMessage”
   android:enabled=“true”
   android:icon=“@drawable/message_icon”
   android:shortcutShortLabel=“@string/message_shortcut_short_label1”
   android:shortcutLongLabel=“@string/message_shortcut_long_label1”
   android:shortcutDisabledMessage=“@string/message_disabled”>
   <intent
     android:action=“android.intent.action.VIEW”
     android:targetPackage=“com.example.myapplication”
     android:targetClass=“com.example.myapplication.NewMessageActivity” />
   <!– If your shortcut is associated with multiple intents, include them
        here. The last intent in the list determines what the user sees when
        they launch this shortcut. –>
   <categories android:name=“android.shortcut.conversation” />
 </shortcut>
 <!– Specify more shortcuts here. –>
</shortcuts>

Here, you can see that we have defined shortcut Long Label and Short Label. Generally short label is displayed for a shortcut. But if your launcher has more space, it will show long label instead.

Inside <intent>, we have defined the activity which should be launched on click of Message Shortcut.

That is it for the static shortcuts. Once you’ll run the app, it will show the defined shortcuts in the above XML.

Create Dynamic Shortcuts

Dynamic shortcuts provide links to specific, context-sensitive actions within your app. Good examples for dynamic shortcuts include calling a specific person, navigating to a specific location, and loading a game from the user’s last save point.

To create dynamic shortcuts, you can add the following code in your app:

ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

ShortcutInfo shortcut = new ShortcutInfo.Builder(context, “personChat”)
   .setShortLabel(“John Doe”)
   .setLongLabel(“Chat with John Doe”)
   .setIcon(Icon.createWithResource(context, R.drawable.icon_avatar))
   .setIntent(intentToChatActivity)
   .build();

shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));

There are 3 useful methods to add, update and delete dynamic app shortcuts:

  1. setDynamicShortcuts() – Used to set a list of shortcuts.
  2. updateShortcuts() – Updated already defined list of shortcuts.
  3. removeDynamicShortcuts() – Used to remove a list of shortcuts.
Dynamic Shortcuts of WhatsApp
Dynamic Shortcuts of WhatsApp

Create Pinned Shortcuts

On Android 8.0 (API level 26) Oreo and higher, you can create pinned shortcuts. Unlike static and dynamic shortcuts, pinned shortcuts appear in supported launchers as separate icons.

To create pinned shortcuts:

 

ShortcutManager mShortcutManager =
       context.getSystemService(ShortcutManager.class);

if (mShortcutManager.isRequestPinShortcutSupported()) {
   // Assumes there’s already a shortcut with the ID “my-shortcut”.
   // The shortcut must be enabled.
   ShortcutInfo pinShortcutInfo =
           new ShortcutInfo.Builder(context, “personChat”).build();

   // Create the PendingIntent object only if your app needs to be notified
   // that the user allowed the shortcut to be pinned. Note that, if the
   // pinning operation fails, your app isn’t notified. We assume here that the
   // app has implemented a method called createShortcutResultIntent() that
   // returns a broadcast intent.
   Intent pinnedShortcutCallbackIntent =
           mShortcutManager.createShortcutResultIntent(pinShortcutInfo);

   // Configure the intent so that your app’s broadcast receiver gets
   // the callback successfully.For details, see PendingIntent.getBroadcast().
   PendingIntent successCallback = PendingIntent.getBroadcast(context, /* request code */ 0,
           pinnedShortcutCallbackIntent, /* flags */ 0);

   mShortcutManager.requestPinShortcut(pinShortcutInfo,
           successCallback.getIntentSender());
}
Static Shortcuts and Pinned Shortcuts
Static Shortcuts and Pinned Shortcuts

How Let’s Nurture helps for building Apps which support App Shortcuts?

Let’s Nurture, a top mobile app development company in India has got the expertise in providing many solutions based applications with E-Commerce and Social Networking. Our team LetsNurture provides best solutions for business (saving time), shopping experience, teaching experience and many more. If you want to know more about this technology in your existing mobile app, get a free consultation from our experts at Let’s Nurture.

If you are interested to learn and explore about 3D Touch Implementation in Android, you can visit Let’s Nurture’s blog on 3D Touch Implementation in Android  

Want to work with us? We're hiring!