Skip to content

Create App Shortcuts on Android 7.1

Dani Mahardhika edited this page Sep 3, 2017 · 3 revisions

1. Download Required Files

Open this link, you will see 4 files, SearchShortcut.java, ic_shortcut_favorite.xml, ic_shortcut_search.xml, and shortcuts.xml. Download all of them.

2. Copy the Files into Your Project

  • Copy file ic_shortcut_favorite.xml and ic_shortcut_search.xml to drawable folder
  • Copy file shortcuts.xml to xml folder
  • Copy file SearchShortcut.java to java\com\your\package\name\activities\

3. Rename Shortcut Package

After copying those files, open SearchShortcut.java, you will notice there's a red mark on line 1 .

package com.dm.wallpaper.board.demo.shortcuts;

Change it to

package com.your.package.name.activities;

After that open shortcuts.xml, take a look on line 36, 37 and 54, 55.

...
<intent
    android:action="android.intent.action.VIEW"
    android:targetPackage="com.dm.wallpaper.board.demo"
    android:targetClass="com.dm.wallpaper.board.demo.shortcuts.SearchShortcut">
</intent>

...

<intent
    android:action="android.intent.action.VIEW"
    android:targetPackage="com.dm.wallpaper.board.demo"
    android:targetClass="com.dm.wallpaper.board.demo.activities.MainActivity">

    <extra
        android:name="position"
        android:value="1" />
</intent>
...
  • Change android:targetPackage="com.dm.wallpaper.board.demo" with your package name android:targetPackage="com.your.package.name".
  • Change android:targetClass="com.dm.wallpaper.board.demo.shortcuts.SearchShortcut" toandroid:targetClass="com.your.package.name.activities.SearchShortcut".
  • Change android:targetClass="com.dm.wallpaper.board.demo.activities.MainActivity" to android:targetClass="com.your.package.name.activities.MainActivity".

4. Add the Shortcuts to Android Manifest

Open AndroidManifest.xml, take a look on line 28.

...
<activity android:name="com.your.package.name.activities.SplashActivity"
    android:launchMode="singleTop"
    android:noHistory="true"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
...

Change it to

...
<activity android:name="com.your.package.name.activities.SplashActivity"
    android:launchMode="singleTop"
    android:noHistory="true"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme">
    <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>
...

Last, add this code to AndroidManifest.xml inside application tag.

<activity android:name="com.your.package.name.activities.SearchShortcut"
    android:theme="@style/WallpaperTheme"
    android:noHistory="true"
    android:excludeFromRecents="true">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
    </intent-filter>
</activity>

Shortcuts is set, make sure you have a device with Android 7.1 to test it.