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:
- RE the
shortcutattributes: These attribute names are exactly the same as Android 7.1 uses, with the single exception that they are not prefixed withandroid:. When API 25 is released and your app targets it, you can just add anandroid: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 sayandroid:shortcutShortLabelbecause the current Android SDK isn't yet aware of such an attribute. - RE the
intentattributes: Be sure to prefix all attributes withandroid:. - You are free to add as many
shortcutitems 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:
Action Launcher saves a copy of your
shorcuts.xmlbased on your app'sversionCode. If you're tweaking yourshortcuts.xmland want to test the changes in Action Launcher, you must ensure Action Launcher is not using a now-stale copy of yourshortcuts.xml. Do this by either:A. Select
Settings -> Folders, Quickcuts & Shutters -> Quickcuts -> Check againto nuke Action Launcher's entire Quickcuts cache.B. Change your app's
versionCodeso that Action Launcher will flush its cache of your old definitions.- Make sure that any
Activityyou point to in yourshortcuts.xmlare 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. - Ensure the icon you define is visible for all versions of Android. I.e, don't put it in a
drawable-v25resource bucket or similar as the Google App currently does (which is why no icons display in Action Launcher for that app's shortcuts). - For reasons that are currently unclear, most of Google's apps define their
shortcuts.xmlin thexml-v22bucket. 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.
