12/14
2016

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.

优秀人才不缺工作机会,只缺适合自己的好机会。但是他们往往没有精力从海量机会中找到最适合的那个。
100offer 会对平台上的人才和企业进行严格筛选,让「最好的人才」和「最好的公司」相遇。
注册 100offer,谈谈你对下一份工作的期待。一周内,收到 5-10 个满足你要求的好机会!