| <html devsite> |
| <head> |
| <title>Widgets/Shortcuts</title> |
| <meta name="project_path" value="/_project.yaml" /> |
| <meta name="book_path" value="/_book.yaml" /> |
| </head> |
| <body> |
| |
| <!-- |
| Copyright 2017 The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <p> |
| The new flow API for adding shortcuts and widgets in Android 8.0 allows |
| application developers to add shortcuts and widgets from inside the app instead |
| of relying on the widget tray. It also deprecates the old method (sending a |
| broadcast) of adding shortcuts for security reasons. |
| </p> |
| <p> |
| Launchers need to support this new implementation so that app developers can |
| rely on the system to add their shortcut or widget. |
| </p> |
| <h2 id="examples-and-source">Examples and source</h2> |
| <p> |
| Docs are available in various system class. References include the following: |
| </p> |
| <ul> |
| <li><b><a |
| href="https://developer.android.com/reference/android/content/pm/ShortcutManager.html">ShortcutManager.java</a></b><br> |
| Publish Pinned shortcut section in header. |
| <li><b>Intent.java</b><br>Javadoc for ACTION_CREATE_SHORTCUT.</li> |
| <li><b>AppWidgetManager.java</b><br>Javadoc for requestPinAppWidget.</li> |
| </ul> |
| <h2 id="implementation">Implementation</h2> |
| <p> |
| Device implementers need to add an activity in their launcher with intent filter actions: |
| </p> |
| <ul> |
| <li><code>android.content.pm.action.CONFIRM_PIN_SHORTCUT</code></li> |
| <li><code>android.content.pm.action.CONFIRM_PIN_APPWIDGET</code></li> |
| </ul> |
| <p> |
| Refer to the <a |
| href="https://developer.android.com/reference/android/content/pm/LauncherApps.html">API |
| documentation</a> for more details. |
| </p> |
| <p> |
| This activity should display a confirmation prompt to the user to add the <a |
| href="https://developer.android.com/reference/android/content/pm/LauncherApps.html">requested |
| widget/shortcut</a> and upon accepting, add the corresponding widget/shortcut on |
| the homescreen. |
| </p> |
| <p> |
| In case of widgets, the <code>accept()</code> call should include the widget ID |
| of the newly added widget. |
| </p> |
| <h3 id="implementing-a-system-ui">Implementing a System UI</h3> |
| <p> |
| Partners need to update their Launcher app using the Launcher3 implementation |
| (<code>packages/apps/Launcher3</code>) as reference. |
| </p> |
| <p> |
| Relevant Launcher3 changes: |
| </p> |
| <ul> |
| <li>Change-Id: I664366822fe8088742faff2cce006239ab0771bc |
| <li>Change-Id: I905532ba44a8898c9c17476f9f75bc309eeb7b41 |
| </ul> |
| <h2 id="validation">Validation</h2> |
| <p> |
| To validate the feature, try to add shortcuts from Chrome or the Contacts app |
| and verify that a proper confirmation prompt is shown. Upon accepting, the icon |
| should get added on the homescreen and Chrome should display a success toast. |
| </p> |
| </body> |
| </html> |
| |
| |