已合并
docs: add updateDesktopShortcutInfo interface doc #154938
kael-zhang创建于 7月9日
docs: add updateDesktopShortcutInfo interface doc #154938
已合并
kael-zhang创建于 7月9日
1 个文件变更+82-0
@@ -187,6 +187,88 @@ struct ShortcutExample {
187}187}
188```188```
189 189 
190+## shortcutManager.updateDesktopShortcutInfo
191+ 
192+updateDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: number): Promise\<void>;
193+ 
194+更新指定用户的快捷方式信息。使用Promise异步回调。
195+ 
196+**起始版本:** 26.1.0
197+ 
198+**系统接口:** 此接口为系统接口。
199+ 
200+**需要权限:** ohos.permission.MANAGE_SHORTCUTS 或 (ohos.permission.MANAGE_SHORTCUTS 和 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS)
201+ 
202+ - 更新应用程序所属用户下的快捷方式时,需要申请ohos.permission.MANAGE_SHORTCUTS。
203+ 
204+ - 更新其他用户下的快捷方式时,需要申请ohos.permission.MANAGE_SHORTCUTS和ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
205+ 
206+**系统能力:** SystemCapability.BundleManager.BundleFramework.Launcher
207+ 
208+**模型约束:** 此接口仅可在Stage模型下使用。
209+ 
210+**参数:**
211+ 
212+| 参数名 | 类型 | 必填 | 说明 |
213+| ---------- | ------ | ---- | -------------- |
214+| shortcutInfo | [ShortcutInfo](js-apis-bundleManager-shortcutInfo.md#shortcutinfo-1) | 是 | 快捷方式信息。 |
215+| userId | number | 是 | 用户id。可以通过[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)接口获取。|
216+ 
217+**返回值:**
218+ 
219+| 类型 | 说明 |
220+| ---------------------------------------- | ------- |
221+| Promise\<void> | Promise对象,无返回结果。 |
222+ 
223+**错误码:**
224+ 
225+以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[包管理子系统通用错误码](errorcode-bundle.md)。
226+ 
227+| 错误码ID | 错误信息 |
228+| -------- | ---------------------------------------- |
229+| 201 | Verify permission denied. |
230+| 202 | Permission denied, non-system app called system api. |
231+| 17700001 | The specified bundle name is not found. |
232+| 17700004 | The specified user ID is not found. |
233+| 17700026 | The specified bundle is disabled. |
234+| 17700061 | The specified app index is invalid. |
235+| 18100002 | The specified shortcut to be updated is not found. |
236+ 
237+**示例:**
pengdongfa
pengdongfapengdongfa8月3日

示例需提供截图

likedislike
238+ 
239+```ts
240+import { shortcutManager } from '@kit.AbilityKit';
241+import { BusinessError } from '@kit.BasicServicesKit';
242+import { hilog } from '@kit.PerformanceAnalysisKit';
243+ 
244+// 请开发者替换为实际的快捷方式信息、用户id。
245+let shortcutInfo: shortcutManager.ShortcutInfo = {
pengdongfa
pengdongfapengdongfa8月3日

这些内容应提醒开发者进行替换

likedislike
246+ id: 'test1',
247+ bundleName: 'com.example.myapplication',
248+ moduleName: '',
249+ hostAbility: '',
250+ icon: '',
251+ iconId: 1,
252+ label: 'hello',
253+ labelId: 1,
254+ wants: [],
255+ appIndex: 0,
256+ sourceType: 0,
257+};
258+ 
259+try {
260+ shortcutManager.updateDesktopShortcutInfo(shortcutInfo, 100)
pengdongfa
pengdongfapengdongfa8月3日

提醒开发者替换id

likedislike
261+ .then(() => {
262+ hilog.info(0x0000, 'testTag', 'updateDesktopShortcutInfo successfully');
263+ }).catch((err: Error) => {
264+ hilog.error(0x0000, 'testTag', 'updateDesktopShortcutInfo failed. Cause: %{public}s', err.message);
265+ });
266+} catch (err) {
267+ let message = (err as BusinessError).message;
268+ hilog.error(0x0000, 'testTag', 'updateDesktopShortcutInfo failed. Cause: %{public}s', message);
269+}
270+```
271+ 
190## shortcutManager.getAllDesktopShortcutInfo272## shortcutManager.getAllDesktopShortcutInfo
191 273 
192getAllDesktopShortcutInfo(userId: number) : Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>274getAllDesktopShortcutInfo(userId: number) : Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>