• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.shortcutManager (shortcutManager模块)
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9本模块提供应用对于[快捷方式](../../quick-start/typical-scenario-configuration.md)的管理能力,包括设置快捷方式是否显示等。
10
11> **说明:**
12>
13> 本模块首批接口从API version 20开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14
15## 导入模块
16
17```ts
18import { shortcutManager } from '@kit.AbilityKit';
19```
20
21## shortcutManager.setShortcutVisibleForSelf
22
23setShortcutVisibleForSelf(id: string, visible: boolean) : Promise\<void>
24
25设置当前应用指定的快捷方式是否显示,使用Promise异步回调。
26
27**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
28
29**参数:**
30
31| 参数名     | 类型   | 必填 | 说明         |
32| ---------- | ------ | ---- | -------------- |
33| id         | string | 是   | 快捷方式的ID,通过[module.json5配置文件](../../quick-start/module-configuration-file.md)中的shortcuts标签下的shortcutId字段获取,取值为长度不超过63字节的字符串。 |
34| visible    | boolean| 是   | 快捷方式是否显示。true:快捷方式显示;false:快捷方式不显示。 |
35
36**返回值:**
37
38| 类型             | 说明              |
39| -------------- | --------------- |
40| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
41
42**错误码:**
43
44以下错误码的详细介绍请参见[包管理子系统通用错误码](errorcode-bundle.md)。
45
46| 错误码ID | 错误信息                                 |
47| -------- | ---------------------------------------- |
48| 17700070 | The specified shortcut id is illegal. |
49
50**示例:**
51
52```ts
53import { shortcutManager } from '@kit.AbilityKit';
54import { BusinessError } from '@kit.BasicServicesKit';
55
56// 请替换为module.json5配置文件中的shortcuts标签下实际配置的shortcutId字段
57shortcutManager.setShortcutVisibleForSelf("shortcut_id", false)
58  .then(() => {
59    console.info('setShortcutVisibleForSelf success');
60  }).catch((err: BusinessError) => {
61  console.error(`setShortcutVisibleForSelf errData is errCode:${err.code}  message:${err.message}`);
62});
63```
64
65## shortcutManager.getAllShortcutInfoForSelf
66
67getAllShortcutInfoForSelf(): Promise\<Array\<ShortcutInfo>>
68
69查询当前应用[配置文件](../../quick-start/module-configuration-file.md#shortcuts标签)中定义的所有快捷方式信息,使用Promise异步回调。
70
71**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
72
73**返回值:**
74
75| 类型                                                         | 说明                                                         |
76| ------------------------------------------------------------ | ------------------------------------------------------------ |
77| Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Promise对象,返回应用配置文件中定义的所有快捷方式信息。 |
78
79**示例:**
80
81```ts
82import { shortcutManager } from '@kit.AbilityKit';
83import { BusinessError } from '@kit.BasicServicesKit';
84
85shortcutManager.getAllShortcutInfoForSelf()
86  .then((data: shortcutManager.ShortcutInfo[]) => {
87    console.info('getAllShortcutInfoForSelf shortcut data is' + JSON.stringify(data));
88  }).catch((err: BusinessError) => {
89    console.error(`getAllShortcutInfoForSelf errData is errCode:${err.code}  message:${err.message}`);
90  });
91```
92## ShortcutInfo
93
94type ShortcutInfo = _ShortcutInfo
95
96应用[module.json5配置文件](../../quick-start/module-configuration-file.md#shortcuts标签)中定义的快捷方式信息。
97
98**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
99
100| 类型                                                         | 说明           |
101| ------------------------------------------------------------ | -------------- |
102| [_ShortcutInfo](./js-apis-bundleManager-shortcutInfo.md#shortcutinfo-1) | 应用module.json5配置文件中定义的快捷方式信息。 |
103
104## ShortcutWant
105
106type ShortcutWant = _ShortcutWant
107
108快捷方式内定义的目标[wants](../../quick-start/module-configuration-file.md#wants标签)信息集合。
109
110**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
111
112| 类型                                                         | 说明           |
113| ------------------------------------------------------------ | -------------- |
114| [_ShortcutWant](./js-apis-bundleManager-shortcutInfo.md#shortcutwant) | 快捷方式内定义的目标[wants](../../quick-start/module-configuration-file.md#wants标签)信息集合。 |
115
116## ParameterItem
117
118type ParameterItem = _ParameterItem
119
120快捷方式配置信息中的自定义数据。
121
122**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
123
124| 类型                                                         | 说明           |
125| ------------------------------------------------------------ | -------------- |
126| [_ParameterItem](./js-apis-bundleManager-shortcutInfo.md#parameteritem) | 快捷方式配置信息中的自定义数据。 |
127