This module provides capabilities to display the app details page and the page for adding an atomic service widget to the home screen, as well as to add, query, and delete home screen shortcuts.
Exceptions need to be captured when an API is called.
Since: 4.1.0(11)
Input parameter to receive the status change during the loading of an app details page.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 4.1.0(11)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| onError | ErrorCallback | No | Yes | Callback function to receive the error code generated when an app details page fails to be loaded. 1011: Failed to launch the app or switch it to the foreground. 1012: Failed to switch the app to the background. 1013: Destruction failed. |
| onAppear | Callback<void> | No | Yes | Callback function, which will be called when the app details page is successfully displayed. Since: 5.0.2(14) |
| onDisappear | Callback<void> | No | Yes | Callback function, which will be called when the app details page is successfully closed. Since: 5.0.2(14) |
Input parameter to receive the status change during the loading of the page for adding an atomic service widget to the home screen.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 4.1.0(11)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| onReceive | Callback<ServiceViewReceiveData> | No | Yes | Callback function called when the atomic service widget is successfully loaded and added to the home screen, providing the related information and result. |
| onError | ErrorCallback | No | Yes | Callback function to receive the error code generated when the page for adding an atomic service widget to the home screen fails to be loaded. 1011: Failed to launch the app or switch it to the foreground. 1012: Failed to switch the app to the background. 1013: Destruction failed. |
| onAppear | Callback<void> | No | Yes | Callback function called when the page for adding an atomic service widget to the home screen is successfully displayed. Since: 5.0.2(14) |
| onDisappear | Callback<void> | No | Yes | Callback function called when the page for adding an atomic service widget to the home screen is closed. Since: 5.0.2(14) |
Callback data returned when an atomic service widget is added to the home screen.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 4.1.0(11)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| result | ReceiveDataResult | Yes | No | Result of adding an atomic service widget to the home screen. |
| msg | string | Yes | No | Result description of adding an atomic service widget to the home screen. |
| formInfo | {[key: string]: Object;} | Yes | No | Data of the atomic service widget added to the home screen. The following attributes are mandatory: - bundleName: package name of the atomic service. - name: widget name. - abilityName: ability name. - moduleName: name of a module in the atomic service. - defaultDimension: widget dimensions. |
Enumerated result codes of adding an atomic service widget to the home screen.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 4.1.0(11)
| Name | Value | Description |
|---|---|---|
| SUCCESS | 1000 | Successful. |
| FAILURE | 1001 | Failed. |
| EXCEPTION | 1002 | An exception occurred. |
Shortcut verification result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| tid | string | No | Yes | Transaction ID generated based on the app shortcut information. If the shortcut information changes, a new tid will be generated each time and overwrite the previous one. Otherwise, the existing tid and the remaining time before expiration (specified by expired) will be returned. |
| expired | number | No | Yes | Remaining time before transaction ID expiration, in milliseconds. |
| code | number | No | No | Verification result code. The value 0 indicates that the verification is successful. For details about the failure cause, please refer to ArkTS API Error Codes. |
| limit | number | No | Yes | Number of shortcuts that can be added for an app. |
Registers ad impression data of the attribution source.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| adTechId | string | No | No | Attribution role ID of a distribution platform. This identifier specifies the distribution platform to which the marketing task of the registered attribution source belongs. This ID is assigned by the app attribution service when a distribution platform registers an attribution role on the cloud platform of the app attribution service. It has a fixed length of eight characters. |
| campaignId | string | No | No | Marketing task ID, which is the ID of the marketing task corresponding to the registered attribution source. The value contains a maximum of six characters. Note: For 6.0.2(22) and later versions, the maximum value length of this parameter will change from six to nine characters. |
| destinationId | string | No | No | ID of the app released on AppGallery. The value contains a maximum of 64 characters. Note: For details about how to obtain your app ID, please refer to Viewing App Basic Information. |
| mmpIds | string[] | No | Yes | Attribution role ID of the attribution monitoring platform used in the current ad delivery task. A maximum of two IDs can be configured. Each ID contains eight characters. If the caller passes the attribution monitoring platform ID, the app attribution service will post back the attribution result to the attribution monitoring platform. Without this ID, the attribution monitoring platform cannot receive the attribution result. |
| serviceTag | string | No | Yes | Business information relevant to the distribution platform, such as information about creatives and assets. The value should not exceed 32 characters. If the caller passes serviceTag, the app attribution service will post back serviceTag to the distribution platform after you enable the permission. |
| nonce | string | No | No | Random string without hyphens (-), used for signature calculations. The value of nonce is unique for each ad request and has a fixed length of 32 characters. For the same adTechId, a single nonce can be used to register the attribution source information for up to five impressions and five clicks. |
| timestamp | number | No | No | Unix timestamp in milliseconds, representing the time when the ad is requested, that is, the time when the ad is delivered. Attribution source registration requires that the value not deviate from the current time by more than 10 minutes. |
| signature | string | No | No | Signature. A distribution platform or media app generates a signature based on the ad information and attribution source signature calculation rules. The value contains a maximum of 800 characters. |
Example:
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'LoadProduct';
@Entry
@Component
struct LoadProduct {
build() {
Column() {
Button("load_product")
.onClick(() => {
try {
// Register ad impression data of the attribution source.
const exposureData: productViewManager.SKExposure = {
// Allocated by the app attribution service when an ad ecosystem partner role is registered on the cloud platform of the app attribution service.
adTechId: '20****e8',
// ID of the marketing task created by the distribution platform.
campaignId: '123456',
// ID of the developer's app released on AppGallery, without letter C.
destinationId: '10******',
// ID of the attribution monitoring platform.
mmpIds: ['2f****5', '2f7***5'],
// Business information relevant to the distribution platform.
serviceTag: '123***2',
// Random string without hyphens (-), used for signature calculations.
nonce: '123***2',
// Timestamp.
timestamp: 1705536488,
// Signature.
signature: 'MEQCIEQlmZ****zKBSE8QnhLTIHZZZ****ZpRqRxHss65Ko****JgJKjdrWdkL****juEx2RmFS7da****ZRVZ8RyMyUXg=='
};
const want: Want = {
parameters: {
bundleName: 'com.huawei.hmsapp.books',
skExposure: exposureData
}
};
// Display an app details page for users to download the app.
productViewManager.loadProduct(this.getUIContext().getHostContext() as common.UIAbilityContext, want, {
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}`);
}
})
.width('100%')
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
} List of home screen shortcut information.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 6.1.1(24)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| shortcutId | string | No | No | ID of the home screen shortcut. |
| icon | string | No | Yes | Icon of the home screen shortcut. |
| iconId | number | No | Yes | Resource ID of the home screen shortcut icon. |
| label | string | No | Yes | Label of the home screen shortcut. |
| labelId | number | No | Yes | Resource ID of the home screen shortcut label defined as a resource index. |
| want | Want | No | Yes | Target want information defined in the home screen shortcut. |
loadProduct(context: common.UIAbilityContext, want: Want, callback?: ProductViewCallback): void
Displays an app details page for users to download the app. This API uses a callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Device behavior differences: For 6.0.1(21) and earlier versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On other devices, it returns error code 401. For 6.0.2(22) and later versions, this API is supported on phones, tablets, PCs/2-in-1 devices, and TVs. On other devices, it returns error code 401.
Since: 4.1.0(11)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context of the app that calls the API. |
| want | Want | Yes | Request parameters for displaying an app details page. parameters is a mandatory attribute and a structure. This structure contains two attributes: - bundleName: name of the app package whose details page needs to be displayed. This attribute is mandatory. - skExposure: ad impression data passed to register an attribution source. This attribute is optional. For details, see the sample code. |
| callback | ProductViewCallback | No | Input parameter to receive the status change during the loading of an app details page. If this parameter is not specified, the error code cannot be obtained when the app details page fails to be loaded. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error. |
Example:
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'LoadProduct';
@Entry
@Component
struct LoadProduct {
build() {
Column() {
Button("load_product")
.onClick(() => {
try {
const want: Want = {
parameters: {
// Enter the name of the app package to be loaded, for example, com.huawei.hmsapp.appgallery.
bundleName: 'com.xxx'
}
};
productViewManager.loadProduct(this.getUIContext().getHostContext() as common.UIAbilityContext, want, {
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
Adds an atomic service widget to the home screen. This API uses a callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Device behavior differences: For 6.0.1(21) and earlier versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On other devices, it returns error code 401. For 6.0.2(22) and later versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. It does not return a response for TVs. On other devices, it returns error code 401.
Since: 4.1.0(11)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context of the app that calls the API. |
| want | Want | Yes | Request parameter for loading the page for adding an atomic service widget to the home screen. The uri parameter is mandatory. Set it to a link for users to add the atomic service widget to the home screen. For details, see the sample code. |
| callback | ServiceViewCallback | No | Input parameter to receive the status change during the loading of the page for adding an atomic service widget to the home screen. If this parameter is not set, no error code will be returned when the page for adding an atomic service widget to the home screen fails to load, nor can the widget addition result be obtained after the user taps the Add to home screen button. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error. |
Example:
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'LoadService';
@Entry
@Component
struct LoadService {
build() {
Column() {
Button("load_service")
.onClick(() => {
try {
const want: Want = {
// Enter the link for users to add an atomic service widget to the home screen.
uri: 'store://appgallery.huawei.com/oper/addhome?referrer=xxxx&id=xxxx&installType=xxxx&s=xxxx'
};
productViewManager.loadService(this.getUIContext().getHostContext() as common.UIAbilityContext, want, {
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>
Checks whether a home screen shortcut can be created using static resources. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Device behavior differences: For 6.0.1(21) and earlier versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On other devices, it returns error code 401. For 6.0.2(22) and later versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On TVs, it returns error code 1006620001. On other devices, it returns error code 401.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context of the app that calls the API. |
| shortcutId | string | Yes | ID of the shortcut. The value is a string with a maximum of 63 bytes. |
| want | Want | Yes | Want information of the target displayed after the shortcut is tapped. |
| labelResName | string | Yes | Label resource index name of the shortcut displayed on the home screen. |
| iconResName | string | Yes | Icon resource index name of the shortcut displayed on the home screen. |
Returns:
| Type | Description |
|---|---|
| Promise<CheckShortcutResult> | Promise used to return the shortcut verification result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 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. |
Example:
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'CheckPinShortcutPermitted';
@Entry
@Component
struct CheckPinShortcutPermitted {
build() {
Column() {
Button("checkPinShortcutPermitted")
.onClick(() => {
try {
const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
const shortcutId = "id_test1"; // Corresponds to shortcutId configured in the shortcuts tag, for example, "shortcutId": "id_test1".
const labelResName = "shortcut"; // Corresponds to the label resource index name configured in the shortcuts tag, for example, "label": "$string:shortcut".
const iconResName = "aa_icon"; // Corresponds to the icon resource index name configured in the shortcuts tag, for example, "icon": "$media:aa_icon".
const want: Want = {
bundleName: "com.example.appgallery.kit.demo",
moduleName: "entry",
abilityName: "EntryAbility",
parameters: {
testKey: "testValue"
}
};
// Check whether a home screen shortcut can be created using static resources and return the shortcut verification result.
productViewManager.checkPinShortcutPermitted(uiContext, shortcutId, want, labelResName, iconResName)
.then((result: productViewManager.CheckShortcutResult) => {
hilog.info(0x0001, TAG, `checkPinShortcutPermitted success result is ${JSON.stringify(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}`);
}
})
.width('100%')
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
} checkPinShortcutPermitted(context: common.UIAbilityContext, shortcutId: string, want: Want, label: string, foregroundIcon: string, backgroundIcon: string): Promise<CheckShortcutResult>
Checks whether a home screen shortcut can be created using custom resources. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Device behavior differences: For 6.0.1(21) and earlier versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On other devices, it returns error code 401. For 6.0.2(22) and later versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On TVs, it returns error code 1006620001. On other devices, it returns error code 401.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context. |
| shortcutId | string | Yes | ID of the shortcut. The value is a string with a maximum of 63 bytes. |
| want | Want | Yes | Want information of the target displayed after the shortcut is tapped. |
| label | string | Yes | Text of the shortcut name displayed on the home screen. The length cannot exceed 255 characters. |
| foregroundIcon | string | Yes | Sandbox address for the icon of the shortcut displayed on the home screen. The icon must be in PNG or WebP format and should not exceed 100 KB. |
| backgroundIcon | string | Yes | Reserved field. Leave it empty. |
Returns:
| Type | Description |
|---|---|
| Promise<CheckShortcutResult> | Promise used to return the shortcut verification result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 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. |
Example:
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'CheckPinShortcutPermitted';
@Entry
@Component
struct CheckPinShortcutPermitted {
build() {
Column() {
Button("checkPinShortcutPermitted")
.onClick(() => {
try {
const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
const shortcutId = `shortcutId_1`;
const want: Want = {
bundleName: "com.example.appgallery.kit.demo",
moduleName: "entry",
abilityName: "EntryAbility",
parameters: {
testKey: "testValue"
}
}
const label = "shortcut";
const foregroundIcon = uiContext.filesDir + "/icon.png";
const backgroundIcon = "";
// Check whether a home screen shortcut can be created using custom resources and return the shortcut verification result.
productViewManager.checkPinShortcutPermitted(uiContext, shortcutId, want, label, foregroundIcon, backgroundIcon)
.then((result: productViewManager.CheckShortcutResult) => {
hilog.info(0x0001, TAG, `checkPinShortcutPermitted success result is ${JSON.stringify(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}`);
}
})
.width('100%')
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
} requestNewPinShortcut(context: common.UIAbilityContext, tid: string): Promise<void>
Requests to create a shortcut on the home screen. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Device behavior differences: For 6.0.1(21) and earlier versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. On other devices, it returns error code 401. For 6.0.2(22) and later versions, this API is supported on phones, tablets, and PCs/2-in-1 devices. It does not return a response for TVs. On other devices, it returns error code 401.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context. |
| tid | string | Yes | tid returned by the shortcut verification result represented by CheckShortcutResult. |
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 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. |
Example:
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'RequestNewPinShortcut';
@Entry
@Component
struct RequestNewPinShortcut {
build() {
Column() {
Button("RequestNewPinShortcut")
.onClick(() => {
try {
const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
const tid = 'xxx'; // Obtain the value through the checkPinShortcutPermitted API.
productViewManager.requestNewPinShortcut(uiContext, 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}`);
}
})
.width('100%')
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
} getPinShortcutInfos(): Promise<PinShortcutInfo[]>
Queries home screen shortcut information. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 6.1.1(24)
Returns:
| Type | Description |
|---|---|
| Promise<PinShortcutInfo[]> | Promise used to return the home screen shortcut information list. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 801 | Capability not supported. |
| 1006620001 | System internal error. |
| 1006620002 | Request to service error. |
Example:
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'GetPinShortcutInfos';
@Entry
@Component
struct GetPinShortcutInfos {
build() {
Column() {
Button("GetPinShortcutInfos")
.onClick(() => {
try {
// Obtain the home screen shortcut information list through the getPinShortcutInfos API.
productViewManager.getPinShortcutInfos()
.then(() => {
hilog.info(0x0001, TAG, `getPinShortcutInfos success.`);
}).catch((error: BusinessError) => {
hilog.error(0x0001, TAG, `getPinShortcutInfos error. code is ${error.code}, message is ${error.message}`);
})
} catch (err) {
hilog.error(0x0001, TAG, `getPinShortcutInfos failed, code is ${err.code}, message is ${err.message}`);
}
})
.width('100%')
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
} removePinShortcut(context: common.UIAbilityContext, shortcutId: string): Promise<void>
Deletes a shortcut from the home screen. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.Distribution.Recommendations
Since: 6.1.1(24)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context. |
| shortcutId | string | Yes | Shortcut ID. |
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 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. |
Example:
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { productViewManager } from '@kit.AppGalleryKit';
const TAG: string = 'RemovePinShortcut';
@Entry
@Component
struct RemovePinShortcut {
build() {
Column() {
Button("RemovePinShortcut")
.onClick(() => {
try {
const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
const shortcutId = 'xxx'; // Obtain the value through the checkPinShortcutPermitted API.
productViewManager.removePinShortcut(uiContext, shortcutId)
.then(() => {
hilog.info(0x0001, TAG, `removePinShortcut success.`);
}).catch((error: BusinessError) => {
hilog.error(0x0001, TAG, `removePinShortcut error. code is ${error.code}, message is ${error.message}`);
})
} catch (err) {
hilog.error(0x0001, TAG, `removePinShortcut failed, code is ${err.code}, message is ${err.message}`);
}
})
.width('100%')
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
}