1page.title=App Shortcuts
2@jd:body
3
4<!--
5    Copyright 2016 The Android Open Source Project
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18-->
19<div id="qv-wrapper">
20  <div id="qv">
21    <h2>In this document</h2>
22    <ol id="auto-toc">
23    </ol>
24  </div>
25</div>
26
27
28<p>
29The Android 7.1.1 release allows developers to define action-specific
30shortcuts in their apps that can be displayed in a launcher. These <a
31href="https://developer.android.com/guide/topics/ui/shortcuts.html">app
32shortcuts</a> let users quickly start common or recommended tasks within an
33app.
34</p>
35
36<h2 id="overview">Overview</h2>
37
38<p>
39Each shortcut references an intent that launches a specific action in the app
40when users select the shortcut. Examples of actions you can express as app
41shortcuts include:
42</p>
43
44<ul>
45  <li>Navigating users to a particular location in a mapping app
46  <li>Sending messages to a friend in a communication app
47  <li>Playing the next episode of a TV show in a media app
48  <li>Loading the last save point in a gaming app</li></ul>
49
50<h2 id="examples-and-source">Examples and source</h2>
51
52<p>
53You can find the primary implementation of this feature in the following files:
54</p>
55
56<pre>frameworks/base/services/core/java/com/android/server/policy/ShortcutManager.java
57frameworks/base/services/core/java/com/android/server/pm/ShortcutPackage.java
58frameworks/base/services/core/java/com/android/server/pm/ShortcutUser.java
59frameworks/base/services/core/java/com/android/server/pm/ShortcutPackageInfo.java
60frameworks/base/services/core/java/com/android/server/pm/ShortcutLauncher.java
61frameworks/base/services/core/java/com/android/server/pm/ShortcutParser.java
62frameworks/base/services/core/java/com/android/server/pm/ShortcutService.java
63frameworks/base/services/core/java/com/android/server/pm/LauncherAppsService.java
64frameworks/base/services/core/java/com/android/server/pm/ShortcutPackageItem.java
65frameworks/base/core/java/com/android/server/backup/ShortcutBackupHelper.java
66frameworks/base/core/java/android/content/pm/ShortcutManager.java
67frameworks/base/core/java/android/content/pm/ShortcutServiceInternal.java
68frameworks/base/core/java/android/content/pm/ShortcutInfo.java
69frameworks/base/core/java/android/content/pm/LauncherApps.java
70</pre>
71
72<p>
73With the following files providing supporting features (called hidden APIs in
74<code>ShortcutManager.java</code>):
75</p>
76
77<pre>
78packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
79frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java
80</pre>
81
82<p>
83And, for an example, the Android Open Source Project Launcher version 3 supports
84shortcuts:
85</p>
86
87<pre>
88packages/apps/Launcher3/
89</pre>
90
91<p>
92Finally, see the following files for public Javadoc.
93</p>
94
95<pre>frameworks/base/core/java/android/content/pm/ShortcutManager.java
96frameworks/base/core/java/android/content/pm/ShortcutInfo.java
97frameworks/base/core/java/android/content/pm/LauncherApps.java
98</pre>
99
100<h2 id="implementation">Implementation</h2>
101
102<p>
103The AOSP Launcher3 supports shortcuts already.  In cases where a partner has its
104own launcher, that launcher should support shortcuts too.
105</p>
106
107<ul>
108  <li>When the user performs a certain gesture (e.g. long press) on an app icon,
109the launcher should show the dynamic and manifest shortcuts associated with each
110launcher activity icon.<br>
111The shortcut sort order is defined in the ShorctutManager Javadoc within
112the "Shortcut Display Order" section.  For example, show the manifest shortcuts
113first, then the dynamic shortcuts.  The shortcuts are sorted by rank in
114ascending order within each group.
115  <li>The user should be able to drag each dynamic/manifest shortcut and "pin" it
116to the home screen.
117  <li>Pinned shortcuts should be backed up and restored. (See ShortcutManager's
118javadoc for details)
119  <li>Doing an "Inline reply" on Notification should internally call
120ShortcutManager.onApplicationActive.
121</ul>
122
123<p>
124In addition, some Google Mobile Services (GMS) apps have shortcuts. The OEM
125launcher should show shortcuts for them and ideally support "<a
126href="https://support.google.com/nexus/answer/6118421">pinning</a>" (or creating
127a shortcut icon) too.
128</p>
129
130<p>
131See the Launcher3 source for details on how to interact with the framework for
132the above operations.
133</p>
134
135<h2 id="validation">Validation</h2>
136
137<p>
138Use the following Android Compatibility Test Suite (CTS) tests to ensure your
139version of the feature (ShortcutManager and LauncherApps) works as intended:
140</p>
141
142<pre>
143cts/tests/tests/shortcutmanager/
144cts/hostsidetests/shortcuts/
145</pre>
146
147<p>
148And find the unit tests for the AOSP implementation here:
149</p>
150
151<pre>frameworks/base/services/tests/servicestests/
152</pre>
153
154<p>
155Which includes:
156</p>
157
158<pre>src/com/android/server/pm/ShortcutManagerTest*.java
159</pre>
160<p>
161You may also employ the CTS Verifier test for shortcut manager:
162</p>
163
164<pre>
165cts/apps/CtsVerifier/src/com/android/cts/verifier/notifications/ShortcutThrottlingResetActivity.java
166</pre>
167