Widgets and shortcuts

The new flow API for adding shortcuts and widgets in Android 8.0 allows app 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.

Launchers need to support this new implementation so that app developers can rely on the system to add their shortcut or widget.

Examples and source

Docs are available in various system class. References include the following:

  • ShortcutManager.java
    Publish Pinned shortcut section in header.
  • Intent.java
    Javadoc for ACTION_CREATE_SHORTCUT.
  • AppWidgetManager.java
    Javadoc for requestPinAppWidget.

Implementation

Device implementers need to add an activity in their launcher with intent filter actions:

  • android.content.pm.action.CONFIRM_PIN_SHORTCUT
  • android.content.pm.action.CONFIRM_PIN_APPWIDGET

Refer to the API documentation for more details.

This activity should display a confirmation prompt to the user to add the requested widget/shortcut and upon accepting, add the corresponding widget/shortcut on the homescreen.

In case of widgets, the accept() call should include the widget ID of the newly added widget.

Implementing a System UI

Partners need to update their Launcher app using the Launcher3 implementation (packages/apps/Launcher3) as reference.

Find the relevant Launcher3 changes in the Android Open Source Project (AOSP):

Validation

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.