智能客服
你问我答,随时在线为你解决问题
提供展示应用/元服务详情页、应用内快捷方式加桌的能力。
调用接口需捕获异常。
起始版本:4.1.0(11)
- import { productViewManager } from '@kit.StoreKit';
在加载应用详情页面时作为入参用于接收加载过程中的状态变化。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:4.1.0(11)
名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
onError | 否 | 是 | 回调函数,接收应用详情页加载失败的错误码。
| |
onAppear | Callback<void> | 否 | 是 | 回调函数,当应用详情页成功打开时回调该方法。 说明 起始版本:5.0.2(14)。 |
onDisappear | Callback<void> | 否 | 是 | 回调函数,当应用详情页关闭时回调该方法。 说明 起始版本:5.0.2(14)。 |
在加载元服务卡片加桌页面时作为入参用于接收加载过程中的状态变化。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:4.1.0(11)
名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
onReceive | Callback<ServiceViewReceiveData> | 否 | 是 | 当打开元服务卡片加桌页成功,点击加桌,收到加桌结果。 |
onError | 否 | 是 | 回调函数,接收元服务卡片加桌页加载失败的错误码。
| |
onAppear | Callback<void> | 否 | 是 | 回调函数,当元服务卡片加桌页成功打开时回调该方法。 说明 起始版本:5.0.2(14)。 |
onDisappear | Callback<void> | 否 | 是 | 回调函数,当元服务卡片加桌页关闭时回调该方法。 说明 起始版本:5.0.2(14)。 |
元服务加桌回调数据。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:4.1.0(11)
名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
result | 是 | 否 | 加桌结果。 | |
msg | string | 是 | 否 | 加桌结果描述信息。 |
formInfo | {[key: string]: Object} | 是 | 否 | 加桌卡片数据。有以下必填属性:
|
元服务加桌结果码类型的枚举。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:4.1.0(11)
名称 | 值 | 说明 |
|---|---|---|
SUCCESS | 1000 | 成功。 |
FAILURE | 1001 | 失败。 |
EXCEPTION | 1002 | 异常。 |
快捷方式校验结果。
模型约束:此接口仅可在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 | 否 | 是 | 允许应用添加快捷方式的数量。 |
登记归因来源的广告曝光数据。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:5.0.2(14)
参数:
名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
adTechId | string | 否 | 否 | 分发平台对应的归因角色ID,本次登记归因来源对应营销任务所归属的分发平台的标识符。 分发平台向应用归因云侧注册归因角色时,由应用归因服务分配,长度固定为8字符。 |
campaignId | string | 否 | 否 | 营销任务ID,登记归因来源对应的营销任务的ID,长度不超过6字符。 |
destinationId | string | 否 | 否 | 应用上架华为应用市场的AppId,长度不超过64个字符。 说明 您的应用ID参考查看应用基本信息获取。 |
mmpIds | string[] | 否 | 是 | 本次广告投放,使用的归因监测平台对应的归因角色ID。最大数量2个,每个ID字符串长度固定为8字符。 如果调用方传递了归因监测平台ID,应用归因服务会向归因监测平台回传归因结果;如果调用方没有传递监测平台ID,则归因监测平台收不到回传的归因结果。 |
serviceTag | string | 否 | 是 | 分发平台关注的业务信息,如创意、素材等,长度不超过32字符。 serviceTag通过白名单方式向分发平台开放,白名单开放方式请联系华为运营。 |
nonce | string | 否 | 否 | 用于计算签名的随机数,不带'-',每次广告请求,nonce唯一。长度固定为32字符。 同一个adTechId,同一个nonce最多可以登记5次曝光,5次点击类型的归因来源信息。 |
timestamp | number | 否 | 否 | unix时间戳,单位:毫秒,请求广告的时间戳。(即广告投放时间,登记归因来源时,要求广告时间与当前时间偏差不超过10分钟) |
signature | string | 否 | 否 | 签名值,分发平台/媒体根据广告相应信息按照归因来源签名计算规则计算生成签名并提供,长度不超过800字符。 |
示例:
- import { productViewManager } from '@kit.StoreKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import type { common, Want } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- try {
- const exposureData: productViewManager.SKExposure = {
- adTechId: '20****e8',
- campaignId: '123456',
- destinationId: '10******',
- mmpIds: ['2f****5', '2f7***5'],
- serviceTag: '123***2',
- nonce: '123***2',
- timestamp: 1705536488,
- signature: 'MEQCIEQlmZ****zKBSE8QnhLTIHZZZ****ZpRqRxHss65Ko****JgJKjdrWdkL****juEx2RmFS7da****ZRVZ8RyMyUXg=='
- };
-
- const request: Want = {
- parameters: {
- bundleName: 'com.huawei.hmsapp.books',
- skExposure: exposureData
- }
- };
- productViewManager.loadProduct(getContext(this) as common.UIAbilityContext, request, {
- onError: (error: BusinessError) => {
- hilog.error(0, 'TAG', `loadProduct onError.code is ${error.code}, message is ${error.message}`);
- }
- });
- } catch (err) {
- hilog.error(0, 'TAG', `loadProduct failed.code is ${err.code}, message is ${err.message}`);
- }
loadProduct(context: common.UIAbilityContext, want: Want, callback?: ProductViewCallback): void
展示应用详情页,下载安装目标应用。使用Callback回调。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:4.1.0(11)
参数:
参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
context | 是 | 调用方应用的上下文。 | |
want | 是 | 展示应用详情页的请求参数。parameters 是该参数中的必填属性,为一个结构体。 该结构体包含两个属性:
| |
callback | 否 | 在加载应用详情页面时作为入参用于接收加载过程中的状态变化。若不填此参数,当加载应用详情页失败时,无法获取失败的错误码。 |
错误码:
以下错误码的详细介绍请参见通用错误码。
错误码ID | 错误信息 |
|---|---|
401 | Parameter error. |
示例:
- import { common, Want } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import { productViewManager } from '@kit.StoreKit';
-
- const TAG: string = 'LoadProduct';
-
- @Entry
- @Component
- struct LoadProduct {
- context = getContext(this) as common.UIAbilityContext;
-
- build() {
- Column() {
- Button("load_product")
- .onClick(() => {
- try {
- const request: Want = {
- parameters: {
- // 此处填入要加载的应用包名,例如: bundleName: "com.huawei.hmsapp.appgallery"
- bundleName: 'com.xxx'
- }
- };
- productViewManager.loadProduct(getContext(this) as common.UIAbilityContext, request, {
- onError: (error: BusinessError) => {
- hilog.error(0, TAG, `loadProduct onError.code is ${error.code}, message is ${error.message}`);
- },
- onAppear: () => {
- hilog.info(0, TAG, `loadProduct onAppear.`);
- },
- onDisappear: () => {
- hilog.info(0, TAG, `loadProduct onDisappear.`);
- }
- });
- } catch (err) {
- hilog.error(0, TAG, `loadProduct failed.code is ${err.code}, message is ${err.message}`);
- }
- })
- .width('100%')
- }
- .margin(16)
- .height('100%')
- .justifyContent(FlexAlign.Center)
- }
- }
loadService(context: common.UIAbilityContext, want: Want, callback?: ServiceViewCallback): void
展示元服务详情页,添加至桌面。使用Callback回调。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:4.1.0(11)
参数:
参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
context | 是 | 调用方应用的上下文。 | |
want | 是 | 加载元服务详情页面接口的请求参数。uri为必填参数,其值为元服务加桌链接。具体可参考下文中的示例代码。 说明 获取元服务加桌链接的说明文档。 | |
callback | 否 | 在加载元服务详情页面时作为入参用于接收加载过程中的状态变化。若不填此参数,当加载元服务详情页失败时,无法返回失败的错误码;当加载元服务详情页成功时,点击加桌,无法获取加桌结果。 |
错误码:
以下错误码的详细介绍请参见通用错误码。
错误码ID | 错误信息 |
|---|---|
401 | Parameter error. |
示例:
- import { common, Want } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import { productViewManager } from '@kit.StoreKit';
-
- const TAG: string = 'LoadService';
-
- @Entry
- @Component
- struct LoadProduct {
- context = getContext(this) as common.UIAbilityContext;
-
- build() {
- Column() {
- Button("load_service")
- .onClick(() => {
- try {
- const request: Want = {
- // 请输入元服务的加桌链接
- uri: 'store://appgallery.huawei.com/oper/addhome?referrer=xxxx&id=xxxx&installType=xxxx&s=xxxx'
- };
- productViewManager.loadService(getContext(this) as common.UIAbilityContext, request, {
- onReceive: (data: productViewManager.ServiceViewReceiveData) => {
- hilog.info(0, 'TAG', `Succeeded in loading Service onReceive.result is ${data.result}, msg is ${data.msg}`);
- },
- onError: (error: BusinessError) => {
- hilog.error(0, 'TAG', `loadService onError.code is ${error.code}, message is ${error.message}`)
- },
- onAppear: () => {
- hilog.info(0, 'TAG', `loadService onAppear.`);
- },
- onDisappear: () => {
- hilog.info(0, 'TAG', `loadService onDisappear.`);
- }
- });
- } catch (err) {
- hilog.error(0, 'TAG', `loadService failed.code is ${err.code}, message is ${err.message}`);
- }
- })
- .width('100%')
- }
- .margin(16)
- .height('100%')
- .justifyContent(FlexAlign.Center)
- }
- }
checkPinShortcutPermitted(context: common.UIAbilityContext, shortcutId: string, want: Want, labelResName: string, iconResName: string): Promise<CheckShortcutResult>
以静态资源方式校验快捷方式是否允许加桌,使用Promise异步回调。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:5.0.2(14)
参数:
参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
context | 是 | 调用方应用的上下文。 | |
shortcutId | string | 是 | 快捷方式ID,取值为长度不超过63字节的字符串。 |
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. |
示例:
- import { productViewManager } from '@kit.StoreKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import type { common, Want } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- try {
- const uiContext = getContext(this) as common.UIAbilityContext;
- const shortcutId = "id_test1"; // 对应shortcuts标签中配置的shortcutId, 例如: "shortcutId": "id_test1"
- const labelResName = "shortcut"; // 对应shortcuts标签中配置的label资源名称, 例如: "label": "$string:shortcut"
- const iconResName = "aa_icon"; // 对应shortcuts标签中配置的icon资源名称, 例如: "icon": "$media:aa_icon"
- const want: Want = {
- bundleName: "com.example.store.kit.demo",
- moduleName: "entry",
- abilityName: "EntryAbility",
- parameters: {
- testKey: "testValue"
- }
- };
- let checkShortcutResult: productViewManager.CheckShortcutResult;
- productViewManager.checkPinShortcutPermitted(uiContext, shortcutId, want, labelResName, iconResName)
- .then((result: productViewManager.CheckShortcutResult) => {
- hilog.info(0x0001, 'TAG', `checkPinShortcutPermitted success result is ${JSON.stringify(result)}`);
- checkShortcutResult = result;
- }).catch((error: BusinessError) => {
- hilog.error(0x0001, 'TAG', `checkPinShortcutPermitted error. code is ${error.code}, message is ${error.message}`);
- })
- } catch (err) {
- hilog.error(0x0001, 'TAG', `checkPinShortcutPermitted failed, code is ${err.code}, message is ${err.message}`);
- }
checkPinShortcutPermitted(context: common.UIAbilityContext, shortcutId: string, want: Want, label: string, foregroundIcon: string, backgroundIcon: string): Promise<CheckShortcutResult>
以自定义资源方式校验快捷方式是否允许加桌,使用Promise异步回调。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:5.0.2(14)
参数:
参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
context | 是 | 上下文。 | |
shortcutId | string | 是 | 快捷方式ID,取值为长度不超过63字节的字符串。 |
want | 是 | 点击快捷方式后被拉起方的want信息。 | |
label | string | 是 | 快捷方式显示在桌面名称的文本,长度不超过255个字符。 |
foregroundIcon | string | 是 | 快捷方式显示在桌面图标的沙箱地址,图标最大不超过100k,格式为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. |
示例:
- import { productViewManager } from '@kit.StoreKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import type { common, Want } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- try {
- const uiContext = getContext(this) as common.UIAbilityContext;
- const shortcutId = `shortcutId_1`;
- const want: Want = {
- bundleName: "com.example.store.kit.demo",
- moduleName: "entry",
- abilityName: "EntryAbility",
- parameters: {
- testKey: "testValue"
- }
- }
- const label = "shortcut";
- const foregroundIcon = uiContext.filesDir + "/icon.png";
- const backgroundIcon = "";
- let checkShortcutResult: productViewManager.CheckShortcutResult;
- productViewManager.checkPinShortcutPermitted(uiContext, shortcutId, want, label, foregroundIcon, backgroundIcon)
- .then(result => {
- hilog.info(0x0001, 'TAG', `checkPinShortcutPermitted success result is ${JSON.stringify(result)}`);
- checkShortcutResult = result;
- }).catch((error: BusinessError) => {
- hilog.error(0x0001, 'TAG', `checkPinShortcutPermitted error. code is ${error.code}, message is ${error.message}`);
- })
- } catch (err) {
- hilog.error(0x0001, 'TAG', `checkPinShortcutPermitted failed, code is ${err.code}, message is ${err.message}`);
- }
requestNewPinShortcut(context: common.UIAbilityContext, tid: string): Promise<void>
创建快捷方式加桌,使用Promise异步回调。
模型约束:此接口仅可在Stage模型下使用。
系统能力:SystemCapability.AppGalleryService.Distribution.Recommendations
起始版本:5.0.2(14)
参数:
参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
context | 是 | 上下文。 | |
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. |
示例:z
- import { productViewManager } from '@kit.StoreKit';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import type { common } from '@kit.AbilityKit';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- try {
- const uiContext = getContext(this) as common.UIAbilityContext;
- productViewManager.requestNewPinShortcut(uiContext, this.tid)
- .then(() => {
- hilog.info(0x0001, 'TAG', `requestNewPinShortcut success.`);
- }).catch((error: BusinessError) => {
- hilog.error(0x0001, 'TAG', `requestNewPinShortcut error. code is ${error.code}, message is ${error.message}`);
- })
- } catch (err) {
- hilog.error(0x0001, 'TAG', `requestNewPinShortcut failed, code is ${err.code}, message is ${err.message}`);
- }