• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Creating a Static Shortcut of the Application
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9With applications getting more feature-packed, it becomes tougher for users to find and use specific features. To make things smoother, you can create home screen shortcuts for popular features in your application, allowing for quick application launch and direct access to these features. Typical feature shortcuts include "Quick Photo" in camera applications, "Create Note" in note applications, and frequently used location navigation in map applications. All of these shortcuts enable users to quickly access specific feature pages, greatly improving operation efficiency and making users more reliant on the application. You can also create shortcuts to meet personalized workflow and preference needs.
10
11## When to Use
12
13This topic uses navigation as an example. When using a map application for navigation, users tend to search for a destination and then start navigation. To make this process more efficient and user-friendly, you can add navigation shortcuts for regular destinations like company or home for the map application. With these shortcuts, users can quickly start navigation by long pressing the application. For details, see [Home Screen Shortcuts](https://developer.huawei.com/consumer/en/doc/best-practices/bpta-desktop-shortcuts).
14
15## How to Configure
16
17The following describes how to configure a static shortcut in a project.
18
191. Add the following content to the **entry/src/main/resources/base/element/string.json** file:
20    ```json
21    {
22      "string": [
23        // ···
24        {
25          "name": "share",
26          "value": "Share"
27        },
28        {
29          "name": "add",
30          "value": "Favorites"
31        }
32      ]
33    }
34    ```
35
36
372. Configure the shortcut file.
38
39    In the **/resources/base/profile/** directory of the module, configure the following fields in the [shortcut](module-configuration-file.md#shortcuts) file, for example, **shortcuts_config.json**. Remove comments from the sample code.
40
41    ```json
42    {
43      "shortcuts": [
44       {
45          "shortcutId": "id_test1",  // Shortcut ID. If an application has multiple shortcuts, this field can be used as the unique identifier of a shortcut. This field cannot be configured using the resource index (**$string**).
46          "label": "$string:add",  // Shortcut name.
47          "icon": "$media:add_icon", // Shortcut icon. You need to add an image named add_icon to entry/src/main/resources/base/media.
48          "wants": [
49            {
50              "bundleName": "com.ohos.hello",   // Bundle name of the component to start.
51              "moduleName": "entry",    // Module name of the component to start.
52              "abilityName": "EntryAbility1",   // Ability name of the component to start.
53              "parameters": {
54                "testKey": "testValue"   // Custom data of the started shortcut.
55              }
56            }
57          ]
58        },
59        {
60          "shortcutId": "id_test2",  // Shortcut ID. If an application has multiple shortcuts, this field can be used as the unique identifier of a shortcut. This field cannot be configured using the resource index (**$string**).
61          "label": "$string:share",  // Shortcut name.
62          "icon": "$media:share_icon", // Shortcut icon. You need to add an image named share_icon to entry/src/main/resources/base/media.
63          "wants": [
64            {
65              "bundleName": "com.ohos.hello",   // Bundle name of the component to start.
66              "moduleName": "entry",    // Module name of the component to start.
67              "abilityName": "EntryAbility",   // Component name of the component to start.
68              "parameters": {
69                "testKey": "testValue"   // Custom data of the started shortcut.
70              }
71            }
72          ]
73        }
74      ]
75    }
76    ```
77
783. Configure **metadata** in the **module.json5** file of the application, which points to the shortcut file.
79
80    ```json
81    {
82      "module": {
83      // ...
84        "abilities": [
85          {
86            "name": "EntryAbility",
87            "srcEntry": "./ets/entryability/EntryAbility.ets",
88            // ...
89            "metadata": [
90              {
91                "name": "ohos.ability.shortcuts",  // Configure a shortcut. The value is fixed at ohos.ability.shortcuts.
92                "resource": "$profile:shortcuts_config"  // Specify the resources of the shortcuts.
93              }
94            ]
95          }
96        ]
97      }
98    }
99    ```
100
101After installing the application, long press the icon on the home screen. The shortcuts (**Favorites** and **Share**) configured by you are displayed above the application icon. Tap a label to start the corresponding component. The following figure shows a static shortcut of an application displayed on the home screen.
102
103<img src="figures/shortcut_display.jpg"/>
104