Third-party launcher how to support Android 7.1 shortcuts feature

Android SDK 7.1 allows App custom Shortcuts, similar to the iOS 3D touch. It will show a shortcut list by long pressing the App in the launcher, click a shortcut to quickly begin an operation, while Shortcut can be dragged to the launcher for fixed.


At present, only 7.1 system launcher support this feature, the third-party launcher can support this feature through the LauncherApps API, this article describes how the third-party launcher access to this feature.
You can download demo ShortcutViewer from Google Play. Screenshots are as follows:
Android Shortcuts Demo
A comprehensive introduction to Shortcuts can be found at:
The first: Android 7.1 new features Shortcuts introduced
The second: Android 7.1 new features Shortcuts some practice and current problems
If you do not understand the basic use of Shortcuts, you can look at the first article above.


1. Manifest supports Home category

Add the category android.intent.category.HOME to the Main&Launcher Activity in AndroidManifest.xml, which represents this is a launcher app, as follows:


2. Set as the default launcher

The Android SDK LauncherApps API requires that only the default launcher be granted access to all application Shortcuts information.


Open theSettings-Apps-Configure apps-Home app, select your own application as the default launcher.


3. Get all the Shortcuts information for each App

Get the App Shortcuts information via LauncherApps.getShortcuts:

The main steps above include:
(1) Check whether has permission to shortcuts information through LauncherApps.hasShortcutHostPermission ();
(2) Gets all installed applications with the ACTION_MAIN & CATEGORY_LAUNCHER Intent via PackageManager.queryIntentActivities (...);
(3) Traverse each eligible ResolveInfo and get its shortcuts via LauncherApps.getShortcuts (...).


Note: There are other ways to get all the ApplicationInfos that can show on the launcher, but the performance is better via PackageManager.queryIntentActivities (...).


LauncherApps.getShortcuts (LauncherApps.ShortcutQuery query, UserHandle user), the two parameters are query and UserHandle that the queried App corresponding.
The queryFlags above means both Dynamic Shortcuts, Static Shortcuts, Pinned Shortcts.


Of course, this feature is only valid for Android SDK 7.1 and above, so it is best to check the system API version before calling the LauncherApps related API.

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

One thought on “Third-party launcher how to support Android 7.1 shortcuts feature