Android App Shortcuts New and Improved

Caren Chang
3 min readJul 7, 2017

--

About a year ago, Android announced App Shortcuts as part of Android 7.1. The basic gist is that a list of shortcuts could now come up when users long-pressed on the app’s launcher icon. This gave developers the ability to bring users to specific parts of their app or perform certain actions all through the launcher.

Example of Pandora’s available shortcuts

More information about the capabilities and implementation of app shortcuts can be found in the following documentations: https://developer.android.com/guide/topics/ui/shortcuts.html https://guides.codepath.com/android/Creating-App-Shortcuts-in-Launcher

However, at Google IO in May 2017, the Google team announced some really cool updates around app shortcuts.

Previously, one of the best things that users were able to do was to pin a shortcut of an app directly to their launch screen (ultimately creating a shortcut of a shortcut).

This was really useful as users can now be one click away from the most common actions that they want to take. However, not much customization was available to users during this process as they were only able to pin shortcuts that the developers had already defined. Luckily, this is no longer the case with some new APIs defined as part of Android O!

There is now a requestPinShortcut() method that comes with ShortcutManager. This method allows apps to dynamically pin either existing shortcuts or entirely new shortcuts to a supported launcher.

// Optional PendingIntent that can be set if your app wants to know
// if the shortcut was successfully pinned

PendingIntent resultPendingIntent = null;
ShortcutInfo pinShortcutInfo =
new ShortcutInfo.Builder(view.getContext(), "shortcutID")
.setIcon(myIcon)
.setShortLabel("MyShortcut")
.setIntent(someIntent)
.build();

mShortcutManager.requestPinShortcut(pinShortcutInfo, resultPendingIntent);

When you call requestPinShortcut(), you automatically get a modal like this:

This is made even better because now apps can now allow users to fully customize the shortcut including the icon, label, and even intent! Here’s a really simple example where I allow the user to set the app shortcut’s title and icon image.

As you can see, I simply took the text from the EditText field, and the selected image and used those to build the shortcut:

ShortcutInfo pinShortcutInfo =
new ShortcutInfo.Builder(view.getContext(), "shortcutID")
.setIcon(getSelectedImageAsIcon())
.setShortLabel(shortcutTitleInput.getText().toString())
.setIntent(myIntent)
.build();

mShortcutManager.requestPinShortcut(pinShortcutInfo, null);

** Note : Previously on Android 7.1, apps were allowed to do something similar to this by broadcasting the INSTALL_SHORTCUT intent (although I don’t recall seeing this on the official documentation). This method of adding a pinned shortcut will no longer work on Android O and developers will instead have to utilize requestPinShortcut().

--

--