Integrating Quickcuts (aka Android 7.1's "launcher shortcuts") into your app

Update (October 6, 2016): I've updated these instructions based on developer feedback. Be sure to read it again in full.

Adding support for Quickcuts (aka Android 7.1's "launcher shortcuts") into your app is extremely simple. As a bonus, very little about these steps are unique/proprietary to Action Launcher. By following these steps, your app will be very well positioned to support Android 7.1's launcher shortcuts when API 25 is released.

1. Define your shortcuts

Create a shortcuts.xml file defining your shortcuts in your xml folder. It should look like so:

<?xml version="1.0" encoding="utf-8"?>
<shortcuts
  xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut icon="@drawable/my_icon" 
        enabled="true" shortcutId="a-unique-string-id"
        shortcutShortLabel="@string/my_short_label"
        shortcutLongLabel="@string/my_long_label">
        <intent android:targetPackage="com.example.myapp"
            android:targetClass="com.example.myapp.MyActivity"
            android:action="android.intent.action.VIEW"
            android:data="http://example.com/some_data"/>
    </shortcut>
    ... <!-- Add subsequent `shortcut` items here --->
</shortcuts>

Notes:

  1. RE the shortcut attributes: These attribute names are exactly the same as Android 7.1 uses, with the single exception that they are not prefixed with android:. When API 25 is released and your app targets it, you can just add an android: prefix to them and they should just work in Pixel Launcher and Action Launcher both. But until your app targets API 25, you can't use say android:shortcutShortLabel because the current Android SDK isn't yet aware of such an attribute.
  2. RE the intent attributes: Be sure to prefix all attributes with android:.
  3. You are free to add as many shortcut items as you like and Action Launcher will support it. We'll have to see how Google end up actually using launcher shortcuts in Pixel Launcher, but I'd be surprised if Pixel Launcher ended up displaying more than 5 such items at a time.

2. Add a definition to AndroidManifest.xml.

Add this to an Activity definition of your chosing:

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

Caveats:

  1. Action Launcher saves a copy of your shorcuts.xml based on your app's versionCode. If you're tweaking your shortcuts.xml and want to test the changes in Action Launcher, you must ensure Action Launcher is not using a now-stale copy of your shortcuts.xml. Do this by either:

    A. Select Settings -> Folders, Quickcuts & Shutters -> Quickcuts -> Check again to nuke Action Launcher's entire Quickcuts cache.

    B. Change your app's versionCode so that Action Launcher will flush its cache of your old definitions.

  2. Make sure that any Activity you point to in your shortcuts.xml are exported (android:exported="true")! Currently some of Google's apps (like Chrome) don't do this, meaning Action Launcher can't load them. Action Launcher hides such shortcuts.
  3. Ensure the icon you define is visible for all versions of Android. I.e, don't put it in a drawable-v25 resource bucket or similar as the Google App currently does (which is why no icons display in Action Launcher for that app's shortcuts).
  4. For reasons that are currently unclear, most of Google's apps define their shortcuts.xml in the xml-v22 bucket. There doesn' appear to be a technical reason why these shortcuts would require Android 5.1 or later to me, but this will presumably become clearer when Android 7.1 is announced.