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

Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.

HMS Core ReferencesGame ServiceClient APIsAppGalleryKit APIsUpdateAppUpdateClient

com.huawei.hms.jos.AppUpdateClient

The AppUpdateClient class defines the methods for functions related to app update. An instance of the AppUpdateClient type is returned when the JosApps.getAppUpdateClient method is called.

Public Method Summary

ReturnMethod
voidcheckAppUpdate(Context context, CheckUpdateCallBack callBack)
Checks for a new version of the app.
voidshowUpdateDialog(Context mContext, ApkUpgradeInfo info,boolean mustBtnOne)
Displays a dialog box prompting app update.
voidreleaseCallBack()
Releases callback.

Public Methods

public void checkAppUpdate(Context context, CheckUpdateCallBack callBack)

After an app is started and initialized or a user proactively checks for update for an app, the app can call this method to check whether a new version is available.

Parameters

Parameter NameParameter Description
contextContext of the app client.
callBackCallback result for checking the version update.

The CheckUpdateCallBack object is defined as follows:

Collapse
Word wrap
Dark theme
Copy code
  1. public interface CheckUpdateCallBack {
  2.       //Obtain the update status information from the AppGallery. For details about parameters in an intent, see the intent table.  
  3.       void onUpdateInfo(Intent intent);
  4.       //The following method is reserved. No handling is required.
  5.       void onMarketInstallInfo(Intent   intent);
  6.       //The following method is reserved. No handling is required.
  7.       void onMarketStoreError(int responseCode);
  8.       //The following method is reserved. No handling is required.
  9.       void onUpdateStoreError(int   responseCode);
  10.   }


intent

Parameter NameObtaining MethodTypeDescription
status

intent.getIntExtra(UpdateKey.STATUS,   DEFAULT_VALUE)

Note: DEFAULT_VALUE is the custom default value when the value of UpdateKey.STATUS cannot be obtained.

intApp update status. The options are as follows:
1: constant value PARAMER_ERROR, indicating that the parameter is incorrect.
2: constant value CONNECT_ERROR, indicating that the network connection is incorrect.
3: constant value NO_UPGRADE_INFO, indicating that no update information is available.
4: constant value CANCEL, indicating that the user cancels the update.
5: constant value INSTALL_FAILED, indicating that the app update fails.
6: constant value CHECK_FAILED, indicating that the update information fails to be queried.
7: constant value HAS_UPGRADE_INFO, indicating that the update information is available.
8: constant value MARKET_FORBID, indicating that the AppGallery is disabled.
9: constant value IN_MARKET_UPDATING, indicating that the app is being updated. This constant value applies only to the progress bar.
rtnCode

intent.getIntExtra(UpdateKey.FAIL_CODE,   DEFAULT_VALUE)

Note: DEFAULT_VALUE is the custom default value when the value of UpdateKey.FAIL_CODE cannot be obtained.

intResult code of the update operation. The options are as follows:
0: normal.
1: No network is available.
2: JSON exception.
3: parameter exception.
4: I/O exception.
5: network exception.
6: unknown error.
7: Obfuscation is not excluded.
reasonintent.getStringExtra(UpdateKey.FAIL_REASON)StringResult code description.
isExitintent.getBooleanExtra(UpdateKey.MUST_UPDATE,   false)booleanIndicates whether the user cancels the update during forcible update. The options are as follows:
true: yes
false: no
buttonStatus

intent.getIntExtra(UpdateKey.BUTTON_STATUS,   DEFAULT_VALUE)

Note: DEFAULT_VALUE is the custom default value when the value of UpdateKey.BUTTON_STATUS cannot be obtained.

intIndicates whether the user chooses to update the app immediately or later during non-forcible update. The options are as follows:
100: The user chooses to update the app later.
101: The user chooses to update the app immediately.
infointent.getSerializableExtra(UpdateKey.INFO)SerializableApp update information. For details, see ApkUpgradeInfo.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. private static class UpdateCallBack implements CheckUpdateCallBack {
  2.    public void onUpdateInfo(Intent intent) {
  3.        if (intent != null) {
  4.            //Update status.
  5.            int status = intent.getIntExtra(UpdateKey.STATUS, -1);
  6.            //Error code. You are advised to record it.
  7.            int rtnCode = intent.getIntExtra(UpdateKey.FAIL_CODE, -1);
  8.            //Failure information. You are advised to record it.
  9.            String reason = intent.getStringExtra(UpdateKey.FAIL_REASON);
  10.            //Whether to forcibly update the app. By pressing the Back button on the pop-up window, the user quits the app.
  11.            boolean isExit = intent.getBooleanExtra(UpdateKey.MUST_UPDATE, false);
  12.            //Update pop-up window, where the user is offered two options: update now and update later.
  13.            int buttonStatus = intent.getIntExtra(UpdateKey.BUTTON_STATUS, -1);
  14.            //Obtain update information.
  15.            Serializable info = intent.getSerializableExtra(UpdateKey.INFO);
  16.            String updateContent = null;
  17.            if (info instanceof ApkUpgradeInfo) {
  18.                ApkUpgradeInfo upgradeInfo = (ApkUpgradeInfo) info;
  19.                //Display update pop-up window.
  20.                client.showUpdateDialog(this, upgradeInfo, false);
  21.                updateContent = upgradeInfo.toString();
  22.                Log.e(TAG, "onUpdateInfo status: " + status + ",failcause: " + rtnCode + ",isExit: "
  23.                        + isExit + ",updateInfo: " + info.toString());
  24.            }
  25.        }
  26.    }
  27.    public void onMarketInstallInfo (Intent intent){
  28.        //Reserved method. No processing is needed.
  29.    }
  30.    public void onMarketStoreError ( int responseCode){
  31.        //Reserved method. No processing is needed.
  32.    }
  33.    public void onUpdateStoreError ( int responseCode){
  34.        //Reserved method. No processing is needed.
  35.    }
  36. }

public void showUpdateDialog(Context mContext, ApkUpgradeInfo info,boolean mustBtnOne)

When detecting that a new version is available for update, an app can call this method to manually trigger the app update pop-up.

Parameters

Parameter nameParameter description
mContextContext of the app client.
infoDetected update information. For details, see ApkUpgradeInfo.
mustBtnOneButtons displayed in the app update pop-up. The options are as follows:
true: The app update pop-up displays only the update button and the user must update the app.
false: The app update pop-up displays both the update and cancel buttons. The user can tap the cancel button to cancel the update.

public void releaseCallBack()

This method is called in destroy to release the callback, avoiding memory leakage. For methods of static internal classes, this method does not need to be called.

This page may contain third-party content. For details, click here.
Search in References
Enter a keyword.