文档管理中心
您当前正在浏览HarmonyOS最新文档,覆盖已发布的所有API版本,可在API参考中筛选您使用的API版本。详细的版本配套关系请参考版本说明
API参考应用服务AppGallery Kit(应用市场服务)ArkTS APIproductViewManager (应用市场推荐)

productViewManager (应用市场推荐)

提供展示应用详情页、添加元服务卡片至桌面,以及添加、查询和删除桌面快捷方式的能力。

说明

调用接口需捕获异常。

起始版本: 4.1.0(11)

导入模块

PhonePC/2in1TabletTV
收起
自动换行
深色代码主题
复制
  1. import { productViewManager } from '@kit.AppGalleryKit';

ProductViewCallback

PhonePC/2in1TabletTV

在加载应用详情页面时作为入参用于接收加载过程中的状态变化。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
onError ErrorCallback

回调函数,接收应用详情页加载失败的错误码。

1011表示拉起/切前台失败。

1012表示切后台失败。

1013表示销毁失败。

onAppear Callback<void>

回调函数,当应用详情页成功打开时回调该方法。

起始版本: 5.0.2(14)

onDisappear Callback<void>

回调函数,当应用详情页关闭时回调该方法。

起始版本: 5.0.2(14)

ServiceViewCallback

PhonePC/2in1TabletTV

在加载元服务卡片添加至桌面页时作为入参用于接收加载过程中的状态变化。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
onReceive Callback<ServiceViewReceiveData> 回调函数,当元服务卡片加载成功并添加至桌面时调用,获取元服务卡片加载成功并添加至桌面后的相关信息和结果。
onError ErrorCallback

回调函数,接收元服务卡片添加至桌面页加载失败的错误码。

1011表示拉起/切前台失败。

1012表示切后台失败。

1013表示销毁失败。

onAppear Callback<void>

回调函数,当元服务卡片添加至桌面页成功打开时回调该方法。

起始版本: 5.0.2(14)

onDisappear Callback<void>

回调函数,当元服务卡片添加至桌面页关闭时回调该方法。

起始版本: 5.0.2(14)

ServiceViewReceiveData

PhonePC/2in1TabletTV

元服务卡片添加至桌面的回调数据。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
result ReceiveDataResult 元服务卡片添加至桌面结果。
msg string 元服务卡片添加至桌面结果描述信息。
formInfo {[key: string]: Object;}

添加至桌面的元服务卡片数据。有以下必填属性:

- bundleName表示元服务包名。

- name表示卡片名称。

- abilityName表示ability名称。

- moduleName表示元服务模块名。

- defaultDimension表示卡片尺寸。

ReceiveDataResult

PhonePC/2in1TabletTV

元服务卡片添加至桌面结果码类型的枚举。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 4.1.0(11)

展开
名称 说明
SUCCESS 1000 成功。
FAILURE 1001 失败。
EXCEPTION 1002 异常。

CheckShortcutResult

PhonePC/2in1TabletTV

快捷方式校验结果。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 5.0.2(14)

展开
名称 类型 只读 可选 说明
tid string 基于应用的快捷方式信息生成的Transaction ID。若快捷方式信息发生变化,则每次覆盖生成新的tid,否则返回历史tid以及剩余过期时间expired。
expired number Transaction ID的过期时间,单位是ms。
code number 校验的结果码,0表示校验成功,否则具体的失败原因,可以参考ArkTS API错误码
limit number 允许应用添加快捷方式的数量。

SKExposure

PhonePC/2in1TabletTV

登记归因来源的广告曝光数据。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 5.0.2(14)

展开
名称 类型 只读 可选 说明
adTechId string

分发平台对应的归因角色ID,本次登记归因来源对应营销任务所归属的分发平台的标识符。

分发平台向应用归因云侧注册归因角色时,由应用归因服务分配,长度固定为8个字符。

campaignId string

营销任务ID,登记归因来源对应的营销任务的ID,长度不超过6个字符。

说明: 从6.0.2(22)开始,该接口支持长度由不超过6个字符变为不超过9个字符。

destinationId string

应用上架华为应用市场的AppId,长度不超过64个字符。

说明: 您的应用ID参考查看应用基本信息获取。

mmpIds string[]

本次广告投放,使用的归因监测平台对应的归因角色ID。最大数量2个,每个ID字符串长度固定为8个字符。

如果调用方传递了归因监测平台ID,应用归因服务会向归因监测平台回传归因结果;如果调用方没有传递监测平台ID,则归因监测平台收不到回传的归因结果。

serviceTag string

分发平台关注的业务信息,如创意、素材等,长度不超过32个字符。

如果调用方传递了serviceTag,在申请开通权限后应用归因服务会将serviceTag回传分发平台。

nonce string

用于计算签名的随机数,不带'-',每次广告请求,nonce唯一。长度固定为32个字符。

同一个adTechId,同一个nonce最多可以登记5次曝光,5次点击类型的归因来源信息。

timestamp number unix时间戳,单位:毫秒,请求广告的时间戳。(即广告投放时间,登记归因来源时,要求广告时间与当前时间偏差不超过10分钟)
signature string 签名值,分发平台/媒体根据广告相应信息按照归因来源签名计算规则计算生成签名并提供,长度不超过800个字符。

示例:

收起
自动换行
深色代码主题
复制
  1. import { common, Want } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'LoadProduct';
  6. @Entry
  7. @Component
  8. struct LoadProduct {
  9. build() {
  10. Column() {
  11. Button("load_product")
  12. .onClick(() => {
  13. try {
  14. // 登记归因来源的广告曝光数据
  15. const exposureData: productViewManager.SKExposure = {
  16. // 在应用归因云侧注册广告生态伙伴角色时,由应用归因服务分配
  17. adTechId: '20****e8',
  18. // 分发平台创建的营销任务id
  19. campaignId: '123456',
  20. // 开发者应用上架华为应用市场的appId,不带C
  21. destinationId: '10******',
  22. // 归因监测平台id
  23. mmpIds: ['2f****5', '2f7***5'],
  24. // 分发平台关注的业务信息
  25. serviceTag: '123***2',
  26. // 用于计算签名的随机数,不带'-'
  27. nonce: '123***2',
  28. // 时间戳
  29. timestamp: 1705536488,
  30. // 签名值
  31. signature: 'MEQCIEQlmZ****zKBSE8QnhLTIHZZZ****ZpRqRxHss65Ko****JgJKjdrWdkL****juEx2RmFS7da****ZRVZ8RyMyUXg=='
  32. };
  33. const request: Want = {
  34. parameters: {
  35. bundleName: 'com.huawei.hmsapp.books',
  36. skExposure: exposureData
  37. }
  38. };
  39. // 展示应用详情页,下载安装目标应用
  40. productViewManager.loadProduct(this.getUIContext().getHostContext() as common.UIAbilityContext, request, {
  41. onError: (error: BusinessError) => {
  42. hilog.error(0, TAG, `loadProduct onError.code is ${error.code}, message is ${error.message}`);
  43. }
  44. });
  45. } catch (err) {
  46. hilog.error(0, TAG, `loadProduct failed.code is ${err.code}, message is ${err.message}`);
  47. }
  48. })
  49. .width('100%')
  50. }
  51. .margin(16)
  52. .height('100%')
  53. .justifyContent(FlexAlign.Center)
  54. }
  55. }

PinShortcutInfo

PhonePC/2in1TabletTV

桌面快捷方式信息列表。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 6.1.1(24)

展开
名称 类型 只读 可选 说明
shortcutId string 桌面快捷方式的ID。
icon string 桌面快捷方式的图标。
iconId number 桌面快捷方式图标的资源ID。
label string 桌面快捷方式的标签信息。
labelId number 桌面快捷方式标签信息为资源索引时的资源ID。
want Want 桌面快捷方式内定义的目标want信息。

productViewManager.loadProduct

PhonePC/2in1TabletTV

loadProduct(context: common.UIAbilityContext, want: Want, callback?: ProductViewCallback): void

展示应用详情页,下载安装目标应用。使用Callback回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

设备行为差异: 对于6.0.1(21)及之前版本,该接口在Phone、Tablet、PC/2in1中可正常使用,在其他设备类型中返回401错误码。对于6.0.2(22)及之后版本,该接口在Phone、Tablet、PC/2in1、TV中均可正常使用,在其他设备类型中返回401错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
context common.UIAbilityContext 调用方应用的上下文。
want Want

展示应用详情页的请求参数。parameters 是该参数中的必填属性,为一个结构体。

该结构体包含两个属性:

- bundleName,必填,表示需要展示详情页的应用包名。

- skExposure,可选,表示需要传递登记归因来源的广告曝光数据。具体参考示例代码。

callback ProductViewCallback 在加载应用详情页面时作为入参用于接收加载过程中的状态变化。若不填此参数,当加载应用详情页失败时,无法获取失败的错误码。

错误码:

以下错误码的详细介绍请参见通用错误码

展开
错误码ID 错误信息
401 Parameter error.

示例:

收起
自动换行
深色代码主题
复制
  1. import { common, Want } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'LoadProduct';
  6. @Entry
  7. @Component
  8. struct LoadProduct {
  9. build() {
  10. Column() {
  11. Button("load_product")
  12. .onClick(() => {
  13. try {
  14. const request: Want = {
  15. parameters: {
  16. // 此处填入要加载的应用包名,例如: bundleName: "com.huawei.hmsapp.appgallery"
  17. bundleName: 'com.xxx'
  18. }
  19. };
  20. productViewManager.loadProduct(this.getUIContext().getHostContext() as common.UIAbilityContext, request, {
  21. onError: (error: BusinessError) => {
  22. hilog.error(0, TAG, `loadProduct onError.code is ${error.code}, message is ${error.message}`);
  23. },
  24. onAppear: () => {
  25. hilog.info(0, TAG, `loadProduct onAppear.`);
  26. },
  27. onDisappear: () => {
  28. hilog.info(0, TAG, `loadProduct onDisappear.`);
  29. }
  30. });
  31. } catch (err) {
  32. hilog.error(0, TAG, `loadProduct failed.code is ${err.code}, message is ${err.message}`);
  33. }
  34. })
  35. .width('100%')
  36. }
  37. .margin(16)
  38. .height('100%')
  39. .justifyContent(FlexAlign.Center)
  40. }
  41. }

productViewManager.loadService

PhonePC/2in1TabletTV

loadService(context: common.UIAbilityContext, want: Want, callback?: ServiceViewCallback): void

添加元服务卡片至桌面。使用Callback回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

设备行为差异: 对于6.0.1(21)及之前版本,该接口在Phone、Tablet、PC/2in1中可正常使用,在其他设备类型中返回401错误码。对于6.0.2(22)及之后版本,该接口在Phone、Tablet、PC/2in1中可正常使用,TV中无响应,在其他设备类型中返回401错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
context common.UIAbilityContext 调用方应用的上下文。
want Want

加载元服务卡片添加至桌面页面接口的请求参数。uri为必填参数,其值为元服务卡片添加至桌面页链接。具体可参考下文中的示例代码。

callback ServiceViewCallback 在加载元服务卡片添加至桌面页面时作为入参用于接收加载过程中的状态变化。若不填此参数,当加载元服务卡片添加至桌面页失败时,无法返回失败的错误码;当加载元服务卡片添加至桌面页成功时,点击添加至桌面,无法获取元服务卡片添加至桌面结果。

错误码:

以下错误码的详细介绍请参见通用错误码

展开
错误码ID 错误信息
401 Parameter error.

示例:

收起
自动换行
深色代码主题
复制
  1. import { common, Want } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'LoadService';
  6. @Entry
  7. @Component
  8. struct LoadService {
  9. build() {
  10. Column() {
  11. Button("load_service")
  12. .onClick(() => {
  13. try {
  14. const request: Want = {
  15. // 请输入元服务卡片添加至桌面的链接
  16. uri: 'store://appgallery.huawei.com/oper/addhome?referrer=xxxx&id=xxxx&installType=xxxx&s=xxxx'
  17. };
  18. productViewManager.loadService(this.getUIContext().getHostContext() as common.UIAbilityContext, request, {
  19. onReceive: (data: productViewManager.ServiceViewReceiveData) => {
  20. hilog.info(0, TAG, `Succeeded in loading Service onReceive.result is ${data.result}, msg is ${data.msg}`);
  21. },
  22. onError: (error: BusinessError) => {
  23. hilog.error(0, TAG, `loadService onError.code is ${error.code}, message is ${error.message}`)
  24. },
  25. onAppear: () => {
  26. hilog.info(0, TAG, `loadService onAppear.`);
  27. },
  28. onDisappear: () => {
  29. hilog.info(0, TAG, `loadService onDisappear.`);
  30. }
  31. });
  32. } catch (err) {
  33. hilog.error(0, TAG, `loadService failed.code is ${err.code}, message is ${err.message}`);
  34. }
  35. })
  36. .width('100%')
  37. }
  38. .margin(16)
  39. .height('100%')
  40. .justifyContent(FlexAlign.Center)
  41. }
  42. }

productViewManager.checkPinShortcutPermitted

PhonePC/2in1TabletTV

checkPinShortcutPermitted(context: common.UIAbilityContext, shortcutId: string, want: Want, labelResName: string, iconResName: string): Promise<CheckShortcutResult>

校验是否允许以静态资源方式在桌面创建快捷方式。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

设备行为差异: 对于6.0.1(21)及之前版本,该接口在Phone、Tablet、PC/2in1中可正常使用,在其他设备类型中返回401错误码。对于6.0.2(22)及之后版本,该接口在Phone、Tablet、PC/2in1中可正常使用,TV中返回1006620001错误码,在其他设备类型中返回401错误码。

起始版本: 5.0.2(14)

参数:

展开
参数名 类型 必填 说明
context common.UIAbilityContext 调用方应用的上下文。
shortcutId string 快捷方式ID,取值为长度不超过63字节的字符串。
want Want 点击快捷方式后被拉起方的want信息。
labelResName string 快捷方式显示在桌面名称的label资源索引名称。
iconResName string 快捷方式显示在桌面图标的icon资源索引名称。

返回值:

展开
类型 说明
Promise<CheckShortcutResult> Promise对象,返回快捷方式校验结果。

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error.
1006620001 System internal error.
1006620002 Request to service error.
1006620003 Shortcut id already exists.
1006620004 The number of shortcuts has reached the maximum.
1006620005 Shortcut verification failed.

示例:

收起
自动换行
深色代码主题
复制
  1. import { common, Want } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'CheckPinShortcutPermitted';
  6. @Entry
  7. @Component
  8. struct CheckPinShortcutPermitted {
  9. build() {
  10. Column() {
  11. Button("checkPinShortcutPermitted")
  12. .onClick(() => {
  13. try {
  14. const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  15. const shortcutId = "id_test1"; // 对应shortcuts标签中配置的shortcutId, 例如: "shortcutId": "id_test1"
  16. const labelResName = "shortcut"; // 对应shortcuts标签中配置的label资源索引名称, 例如: "label": "$string:shortcut"
  17. const iconResName = "aa_icon"; // 对应shortcuts标签中配置的icon资源索引名称, 例如: "icon": "$media:aa_icon"
  18. const want: Want = {
  19. bundleName: "com.example.appgallery.kit.demo",
  20. moduleName: "entry",
  21. abilityName: "EntryAbility",
  22. parameters: {
  23. testKey: "testValue"
  24. }
  25. };
  26. // 校验是否允许以静态资源方式在桌面创建快捷方式,并返回快捷方式校验结果
  27. productViewManager.checkPinShortcutPermitted(uiContext, shortcutId, want, labelResName, iconResName)
  28. .then((result: productViewManager.CheckShortcutResult) => {
  29. hilog.info(0x0001, TAG, `checkPinShortcutPermitted success result is ${JSON.stringify(result)}`);
  30. }).catch((error: BusinessError) => {
  31. hilog.error(0x0001, TAG, `checkPinShortcutPermitted error. code is ${error.code}, message is ${error.message}`);
  32. })
  33. } catch (err) {
  34. hilog.error(0x0001, TAG, `checkPinShortcutPermitted failed, code is ${err.code}, message is ${err.message}`);
  35. }
  36. })
  37. .width('100%')
  38. }
  39. .margin(16)
  40. .height('100%')
  41. .justifyContent(FlexAlign.Center)
  42. }
  43. }

productViewManager.checkPinShortcutPermitted

PhonePC/2in1TabletTV

checkPinShortcutPermitted(context: common.UIAbilityContext, shortcutId: string, want: Want, label: string, foregroundIcon: string, backgroundIcon: string): Promise<CheckShortcutResult>

校验是否允许以自定义资源方式在桌面创建快捷方式。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

设备行为差异: 对于6.0.1(21)及之前版本,该接口在Phone、Tablet、PC/2in1中可正常使用,在其他设备类型中返回401错误码。对于6.0.2(22)及之后版本,该接口在Phone、Tablet、PC/2in1中可正常使用,TV中返回1006620001错误码,在其他设备类型中返回401错误码。

起始版本: 5.0.2(14)

参数:

展开
参数名 类型 必填 说明
context common.UIAbilityContext 上下文。
shortcutId string 快捷方式ID,取值为长度不超过63字节的字符串。
want Want 点击快捷方式后被拉起方的want信息。
label string 快捷方式显示在桌面名称的文本,长度不超过255个字符。
foregroundIcon string 快捷方式显示在桌面图标的沙箱地址,图标最大不超过100KB,格式为png和webp。
backgroundIcon string 预留字段,目前只支持传入空字符串。

返回值:

展开
类型 说明
Promise<CheckShortcutResult> Promise对象,返回快捷方式校验结果。

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error.
1006620001 System internal error.
1006620002 Request to service error.
1006620003 Shortcut id already exists.
1006620004 The number of shortcuts has reached the maximum.
1006620005 Shortcut verification failed.

示例:

收起
自动换行
深色代码主题
复制
  1. import { common, Want } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'CheckPinShortcutPermitted';
  6. @Entry
  7. @Component
  8. struct CheckPinShortcutPermitted {
  9. build() {
  10. Column() {
  11. Button("checkPinShortcutPermitted")
  12. .onClick(() => {
  13. try {
  14. const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  15. const shortcutId = `shortcutId_1`;
  16. const want: Want = {
  17. bundleName: "com.example.appgallery.kit.demo",
  18. moduleName: "entry",
  19. abilityName: "EntryAbility",
  20. parameters: {
  21. testKey: "testValue"
  22. }
  23. }
  24. const label = "shortcut";
  25. const foregroundIcon = uiContext.filesDir + "/icon.png";
  26. const backgroundIcon = "";
  27. // 校验是否允许以自定义资源方式在桌面创建快捷方式,返回快捷方式校验结果
  28. productViewManager.checkPinShortcutPermitted(uiContext, shortcutId, want, label, foregroundIcon, backgroundIcon)
  29. .then((result: productViewManager.CheckShortcutResult) => {
  30. hilog.info(0x0001, TAG, `checkPinShortcutPermitted success result is ${JSON.stringify(result)}`);
  31. }).catch((error: BusinessError) => {
  32. hilog.error(0x0001, TAG, `checkPinShortcutPermitted error. code is ${error.code}, message is ${error.message}`);
  33. })
  34. } catch (err) {
  35. hilog.error(0x0001, TAG, `checkPinShortcutPermitted failed, code is ${err.code}, message is ${err.message}`);
  36. }
  37. })
  38. .width('100%')
  39. }
  40. .margin(16)
  41. .height('100%')
  42. .justifyContent(FlexAlign.Center)
  43. }
  44. }

productViewManager.requestNewPinShortcut

PhonePC/2in1TabletTV

requestNewPinShortcut(context: common.UIAbilityContext, tid: string): Promise<void>

请求在桌面创建快捷方式。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

设备行为差异: 对于6.0.1(21)及之前版本,该接口在Phone、Tablet、PC/2in1中可正常使用,在其他设备类型中返回401错误码。对于6.0.2(22)及之后版本,该接口在Phone、Tablet、PC/2in1中可正常使用,TV中无响应,在其他设备类型中返回401错误码。

起始版本: 5.0.2(14)

参数:

展开
参数名 类型 必填 说明
context common.UIAbilityContext 上下文。
tid string 快捷方式校验结果CheckShortcutResult返回的tid。

返回值:

展开
类型 说明
Promise<void> Promise对象。无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error.
1006620001 System internal error.
1006620003 Shortcut id already exists.
1006620004 The number of shortcuts has reached the maximum.
1006620005 Shortcut verification failed.
1006620006 The shortcut is not verified or has expired.
1006620007 User refused to add shortcut.

示例:

收起
自动换行
深色代码主题
复制
  1. import { common } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'RequestNewPinShortcut';
  6. @Entry
  7. @Component
  8. struct RequestNewPinShortcut {
  9. build() {
  10. Column() {
  11. Button("RequestNewPinShortcut")
  12. .onClick(() => {
  13. try {
  14. const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  15. const tid = 'xxx'; // 通过checkPinShortcutPermitted接口获取
  16. productViewManager.requestNewPinShortcut(uiContext, tid)
  17. .then(() => {
  18. hilog.info(0x0001, TAG, `requestNewPinShortcut success.`);
  19. }).catch((error: BusinessError) => {
  20. hilog.error(0x0001, TAG, `requestNewPinShortcut error. code is ${error.code}, message is ${error.message}`);
  21. })
  22. } catch (err) {
  23. hilog.error(0x0001, TAG, `requestNewPinShortcut failed, code is ${err.code}, message is ${err.message}`);
  24. }
  25. })
  26. .width('100%')
  27. }
  28. .margin(16)
  29. .height('100%')
  30. .justifyContent(FlexAlign.Center)
  31. }
  32. }

productViewManager.getPinShortcutInfos

PhonePC/2in1TabletTV

getPinShortcutInfos(): Promise<PinShortcutInfo[]>

查询桌面快捷方式信息。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 6.1.1(24)

返回值:

展开
类型 说明
Promise<PinShortcutInfo[]> Promise对象。返回查询桌面快捷方式信息列表的结果。

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
801 Capability not supported.
1006620001 System internal error.
1006620002 Request to service error.

示例:

收起
自动换行
深色代码主题
复制
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import { productViewManager } from '@kit.AppGalleryKit';
  4. const TAG: string = 'GetPinShortcutInfos';
  5. @Entry
  6. @Component
  7. struct GetPinShortcutInfos {
  8. build() {
  9. Column() {
  10. Button("GetPinShortcutInfos")
  11. .onClick(() => {
  12. try {
  13. // 通过getPinShortcutInfos接口获取桌面快捷方式列表信息
  14. productViewManager.getPinShortcutInfos()
  15. .then(() => {
  16. hilog.info(0x0001, TAG, `getPinShortcutInfos success.`);
  17. }).catch((error: BusinessError) => {
  18. hilog.error(0x0001, TAG, `getPinShortcutInfos error. code is ${error.code}, message is ${error.message}`);
  19. })
  20. } catch (err) {
  21. hilog.error(0x0001, TAG, `getPinShortcutInfos failed, code is ${err.code}, message is ${err.message}`);
  22. }
  23. })
  24. .width('100%')
  25. }
  26. .margin(16)
  27. .height('100%')
  28. .justifyContent(FlexAlign.Center)
  29. }
  30. }

productViewManager.removePinShortcut

PhonePC/2in1TabletTV

removePinShortcut(context: common.UIAbilityContext, shortcutId: string): Promise<void>

删除桌面快捷方式。使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AppGalleryService.Distribution.Recommendations

起始版本: 6.1.1(24)

参数:

展开
参数名 类型 必填 说明
context common.UIAbilityContext 上下文。
shortcutId string 快捷方式ID。

返回值:

展开
类型 说明
Promise<void> Promise对象。无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
801 Capability not supported.
1006620001 System internal error.
1006620010 The shortcut ID does not exist.
1006620011 Invalid context.
1006620012 Invalid shortcutId.
1006620013 The user refused to delete the shortcut.
1006620014 Invalid number of parameters.

示例:

收起
自动换行
深色代码主题
复制
  1. import { common } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { productViewManager } from '@kit.AppGalleryKit';
  5. const TAG: string = 'RemovePinShortcut';
  6. @Entry
  7. @Component
  8. struct RemovePinShortcut {
  9. build() {
  10. Column() {
  11. Button("RemovePinShortcut")
  12. .onClick(() => {
  13. try {
  14. const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  15. const shortcutId = 'xxx'; // 通过checkPinShortcutPermitted接口获取
  16. productViewManager.removePinShortcut(uiContext, shortcutId)
  17. .then(() => {
  18. hilog.info(0x0001, TAG, `removePinShortcut success.`);
  19. }).catch((error: BusinessError) => {
  20. hilog.error(0x0001, TAG, `removePinShortcut error. code is ${error.code}, message is ${error.message}`);
  21. })
  22. } catch (err) {
  23. hilog.error(0x0001, TAG, `removePinShortcut failed, code is ${err.code}, message is ${err.message}`);
  24. }
  25. })
  26. .width('100%')
  27. }
  28. .margin(16)
  29. .height('100%')
  30. .justifyContent(FlexAlign.Center)
  31. }
  32. }
在 API参考 中进行搜索
请输入您想要搜索的关键词