We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesApplication ServicesAppGallery KitUpdate on AppGallery

Update on AppGallery

This feature provides version detection and in-app update reminders for apps that have been released, so that you can notify users of the latest version.

Use Cases

After your app is launched or when a user proactively checks for a new version, you can use this service to determine if an update is available. If there is a new version, this service can display update reminders to users.

Service Process

  1. The app calls the API for checking for updates.

  2. The API returns the result about whether a new version is available.

  3. Call the API for displaying an update pop-up.

  4. The display result is returned to the app.

Constraints

  • The Update on AppGallery feature supports phones, tablets, and PCs/2-in-1 devices. Support for TVs is available starting from 5.1.1(19), and for wearables starting from 6.0.0(20).

  • The Update on AppGallery feature does not support the Emulator. Use a real device for debugging. If you use this service in the Emulator, the message "Unable to load content. Tap the screen to retry." will be displayed.

  • The app must have been released on AppGallery.

API Description

The Update on AppGallery feature provides the following APIs. For details, please refer to the API reference.

Expand
API Description
checkAppUpdate(context: common.UIAbilityContext): Promise<CheckUpdateResult> Detects whether a new version is available.
showUpdateDialog(context:common.UIAbilityContext): Promise<ShowUpdateResultCode> Displays an update pop-up.

Development Procedure

Detecting Whether a New App Version Is Available

  1. Import the updateManager module and related common modules.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { updateManager } from '@kit.AppGalleryKit';
    2. import { hilog } from '@kit.PerformanceAnalysisKit';
    3. import type { common } from '@kit.AbilityKit';
    4. import { BusinessError } from '@kit.BasicServicesKit';
  2. Construct an input parameter, which is a context of the common.UIAbilityContext type.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  3. Call the checkAppUpdate API to check whether a new app version is available.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. try {
    2. updateManager.checkAppUpdate(context)
    3. .then((checkResult: updateManager.CheckUpdateResult) => {
    4. hilog.info(0, 'TAG', 'Succeeded in checking Result updateAvailable:' + checkResult.updateAvailable);
    5. }).catch((error: BusinessError) => {
    6. hilog.error(0, 'TAG', `checkAppUpdate onError.code is ${error.code}, message is ${error.message}`);
    7. });
    8. } catch (error) {
    9. hilog.error(0, 'TAG', `checkAppUpdate onError.code is ${error.code}, message is ${error.message}`);
    10. }
NOTE
  • An update can be detected only if the locally installed version is lower than the version released on AppGallery.

  • The signature of the locally installed version must be the same as that of the version released on AppGallery.

  • Currently, closed testing and open testing are not supported.

Displaying an Update Pop-up

  1. Import the updateManager module and related common modules.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { updateManager } from '@kit.AppGalleryKit';
    2. import { hilog } from '@kit.PerformanceAnalysisKit';
    3. import type { common } from '@kit.AbilityKit';
    4. import { BusinessError } from '@kit.BasicServicesKit';
  2. Construct an input parameter, which is a context of the common.UIAbilityContext type.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  3. Call the showUpdateDialog API to display the update pop-up.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. try {
    2. updateManager.showUpdateDialog(context)
    3. .then((resultCode: updateManager.ShowUpdateResultCode) => {
    4. hilog.info(0, 'TAG', 'Succeeded in showing UpdateDialog resultCode:' + resultCode);
    5. })
    6. .catch((error: BusinessError) => {
    7. hilog.error(0, 'TAG', `showUpdateDialog onError.code is ${error.code}, message is ${error.message}`);
    8. });
    9. } catch (error) {
    10. hilog.error(0, 'TAG', `showUpdateDialog onError.code is ${error.code}, message is ${error.message}`);
    11. }
Search in Guides
Enter a keyword.