If app targets Android 7.1(API level 25) or higher, we can define App Shortcuts.
In this post, introduce you What is App Shortcuts, How to implementation that and whether or not has been actually used that.
What are App Shortcuts?

App Shortcuts
App Shortcuts
is the shortcut that can use at the launcher.
According to Google’s API Guide, there are examples of usage as follows.
- Navigating users to a particular location in a mapping app.
- Sending messages to a friend in a communication app.
- Playing the next episode of a TV show in a media app.
- Loading the last save point in a gaming app.
Each of shortcuts provides specific action in your app, when user selects the one.
How to implement App Shortcuts
We can publish two different types of shortcuts for our app.The one is Static
, the other is Dynamic
.
build.gladle settings
As mentioned at the beginning, App Shortcuts needs Android 7.1(API level 25).
Write targetSdkVersion 25
to build.gradle like this.
1 2 3 4 5 6 7 8 9 10 11 |
android { compileSdkVersion 25 buildToolsVersion "25.0.0" defaultConfig { applicationId "com.bowyer.app.appshortcuts" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } |
Static Shortcuts
Static shortcut
is a shortcut that will not be changed depending on the state of the app etc.

Example of Static Shortcuts
No matter what you have many google account or not,Camera app no need to change short cut.
So, you should choice Static shortcuts
.
Static shortcuts
is easy to introduce.
Create shortcuts.xml
You create shortcuts.xml
under res/xml/shortcuts.xml.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <shortcut android:shortcutId="compose" android:enabled="true" android:icon="@drawable/compose_icon" android:shortcutShortLabel="@string/compose_shortcut_short_label1" android:shortcutLongLabel="@string/compose_shortcut_long_label1" android:shortcutDisabledMessage="@string/compose_disabled_message1"> <intent android:action="android.intent.action.VIEW" android:targetPackage="com.example.myapplication" android:targetClass="com.example.myapplication.ComposeActivity" /> <!-- If your shortcut is associated with multiple intents, include them here. The last intent in the list determines what the user sees when they launch this shortcut. --> <categories android:name="android.shortcut.conversation" /> </shortcut> <!-- Specify more shortcuts here. --> </shortcuts> |
Add meta-data to AndroidManifest.xml
You need to write it between activity tag.And the activity tag need android.intent.action.MAIN
action and android.intnet.category.LAUNCHER
category.
If not contains that action or category, can’t launch from App Shortcuts
.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication"> <application ... > <activity android:name="MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" /> </activity> </application> </manifest> |
Dynamic Shortcuts
Dynamic shortcuts
is a shortcut that will be changed depending on the state of the app etc.

Example of Dynamic Shortcuts
If you have three Google Accounts, Gmail app’s shows four shortcuts.
One is create new mail,the other shortcuts create new mail with selected account.
In this case you need to create it dynamically.
Dynamic shortcuts
is easy to introduce too.
Get ShortcutManager
First get ShortcutManager instance from systemservice.
1 |
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); |
Second create ShortcutInfo
as many as you need.
Put Activity.class into the Intent
as you want to launch.
1 2 3 4 5 6 7 |
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1") .setShortLabel("Web site") .setLongLabel("Open the web site") .setIcon(Icon.createWithResource(context, R.drawable.icon_website)) .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.mysite.example.com/"))) .build(); |
Last set these shortcutInfos as a list to the shortcutManager instance.
1 |
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut)); |
That’s all.
※ShortcutManager
needs API level 25, if your apps support lowyer than API level 25.Devide these process another method, and add @TargetApi(25)
.And before call method, you should check if API level is higher than 25.
Example of App Shortcuts

Navigation Drawer
This is my app KyudoScoreBook.This app have NavigationDrawer.
I want to set these menu to App Shortcuts.
NavigationDrawer usually one Activity controls some Fragments.
App ShortCuts or googlesamples/android-AppShortcuts isn’t introduce how to call Activity with intent that has extra values about Static Shortcuts
.
I found the solution of these problem.
Put extra values into intent of Static Shortcuts xml
First put extra values into intent of Static Shortcuts xml.
Intent tag can include extra value like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <shortcut android:enabled="true" android:icon="@drawable/ic_short_record" android:shortcutId="shortcut_record" android:shortcutLongLabel="@string/shortcut_record" android:shortcutShortLabel="@string/shortcut_record"> <intent android:action="android.intent.action.VIEW" android:targetClass="com.bowyer.app.appshortcuts.ui.activity.MainActivity" android:targetPackage="com.bowyer.app.appshortcuts"> <extra android:name="shortcut_id" android:value="RecordTabFragment"/> </intent> <categories android:name="android.shortcut.conversation"/> </shortcut> <shortcut android:enabled="true" android:icon="@drawable/ic_short_memo" android:shortcutId="shortcut_memos" android:shortcutLongLabel="@string/shortcut_memo_list" android:shortcutShortLabel="@string/shortcut_memo_list"> <intent android:action="android.intent.action.VIEW" android:targetClass="com.bowyer.app.appshortcuts.ui.activity.MainActivity" android:targetPackage="com.bowyer.app.appshortcuts"> <extra android:name="shortcut_id" android:value="MemoListFragment"/> </intent> <categories android:name="android.shortcut.conversation"/> </shortcut> </shortcuts> |
Handle intent
Second, handle intent and catch extra values at MainActivity.
※All of App Shortcuts calls MainActivity about my apps.
1 2 3 4 5 6 7 8 9 |
private static final String KEY_SHORTCUT_ID = "shortcut_id"; ・・・ private void handleShortcutsAction() { boolean hasExtra = getIntent().hasExtra(KEY_SHORTCUT_ID); if (!hasExtra) { return; } String shortcutId = getIntent().getStringExtra(KEY_SHORTCUT_ID); ・・・ |
Change Fragment
Last, depending on the extra value to change the fragment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
String shortcutId = getIntent().getStringExtra(KEY_SHORTCUT_ID); // 取得したshortcutIdからどのFragmentを起動するか決める Page page = Page.forMenuId(shortcutId); switch (page.getMenuId()) { case R.id.nav_record: pageChange(RecordTabFragment.newInstance()); break; case R.id.nav_memo: pageChange(MemoListFragment.newInstance()); break; case R.id.nav_chart: pageChange(ChartFragment.newInstance()); break; case R.id.nav_notification: pageChange(NotificationFragment.newInstance()); break; case R.id.nav_fortune: pageChange(FortuneFragment.newInstance()); break; } // Navigation Drawerを選択状態にする navigationView.setCheckedItem(page.getMenuId()); |
That’s all.
This is my sample code about App Shortcuts.
Actually used App Shortcuts?
It is doubtful whether it is really used.
I will show you my apps analytics data of App Shortcuts events.
Information for the B for reference KyudoScoreBook.
■Total downloads : 15,000
■DAU : 1,000
■Android 7.1 user : 1%(10 people /day)

App Shortcuts event
It is not used at all lol.