Android: App Shortcuts

June 7, 2018

App Shortcuts Title Image

Starting from Android 7.1 Google added App Shortcuts to Android. When you use a launcher that supports them, you can longpress an app icon and then you will see a floating widget with useful shortcuts.

Static shortcuts

You have the option to choose between static and dynamic shortcuts. When you already know, that only those few shortcuts will be available and there will be no change, you are good to go with the static ones.

To begin with you have to add a reference to your app’s AndroidManifest.xml to the activity that has the Launcher category:

        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />

    <meta-data android:name=""
        android:resource="@xml/shortcuts" />

And then you just have to create your shortcuts.xml file

<shortcuts xmlns:android=""
    <!-- Add more shortcuts here -->

Don’t forget that you can add just up to 5 shortcuts, more will crash the app.

Dynamic shortcuts

This option might be more interesting for the most of the developers out ther, because it allows you to add user related shortcuts and actions. A special shortcut for pro useres or a quick access shortcut to your favorite book? No problem!

private void makeShortcuts() {
  if (Build.VERSION.SDK_INT >= 25) {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

    Intent intent1 = new Intent(getApplicationContext(), ShortcutHandler.class); //specify a intent to use with the shortcut

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcuts_id")
        .setLongLabel("This is the shortcuts name")
        .setIcon(Icon.createWithResource(context, R.drawable.icon_shortcut))

    //you can ofcourse create more than 1 shortcut, but keep in mind that it is not possible to create more than 5
    //just add them also to the List that you pass to setDynamicShortcuts


Now that you know how to create new shortcuts you can also


.updateShortcuts(List<ShortcutInfo>) They need to have the same id

.removeDynamicShortcuts(List<String>) Remove all shortcuts with specified id

.removeAllDynamicShortcuts() Remove all shortcuts

Disable/Enable shortcuts

Sometimes a user might not be allowed to use a shortcut, for example when he logged out or a trial expired:

.disableShortcuts(List<String>) or you can also define a disabled message:

.disableShortcuts(List<String>, “Sorry, you have to log in!”)

To (re-)enable the shortcuts just call .enableShortcuts(List<String>)