Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.
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.
| Return | Method |
| void | checkAppUpdate(Context context, CheckUpdateCallBack callBack) Checks for a new version of the app. |
| void | showUpdateDialog(Context mContext, ApkUpgradeInfo info,boolean mustBtnOne) Displays a dialog box prompting app update. |
| void | releaseCallBack() Releases 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 Name | Parameter Description |
| context | Context of the app client. |
| callBack | Callback result for checking the version update. The CheckUpdateCallBack object is defined as follows: |
| Parameter Name | Obtaining Method | Type | Description |
|---|---|---|---|
| status | intent.getIntExtra(UpdateKey.STATUS, DEFAULT_VALUE) Note: DEFAULT_VALUE is the custom default value when the value of UpdateKey.STATUS cannot be obtained. | int | App 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. | int | Result 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. |
| reason | intent.getStringExtra(UpdateKey.FAIL_REASON) | String | Result code description. |
| isExit | intent.getBooleanExtra(UpdateKey.MUST_UPDATE, false) | boolean | Indicates 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. | int | Indicates 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. |
| info | intent.getSerializableExtra(UpdateKey.INFO) | Serializable | App update information. For details, see ApkUpgradeInfo. |
Example
- private static class UpdateCallBack implements CheckUpdateCallBack {
- public void onUpdateInfo(Intent intent) {
- if (intent != null) {
- //Update status.
- int status = intent.getIntExtra(UpdateKey.STATUS, -1);
- //Error code. You are advised to record it.
- int rtnCode = intent.getIntExtra(UpdateKey.FAIL_CODE, -1);
- //Failure information. You are advised to record it.
- String reason = intent.getStringExtra(UpdateKey.FAIL_REASON);
- //Whether to forcibly update the app. By pressing the Back button on the pop-up window, the user quits the app.
- boolean isExit = intent.getBooleanExtra(UpdateKey.MUST_UPDATE, false);
- //Update pop-up window, where the user is offered two options: update now and update later.
- int buttonStatus = intent.getIntExtra(UpdateKey.BUTTON_STATUS, -1);
- //Obtain update information.
- Serializable info = intent.getSerializableExtra(UpdateKey.INFO);
- String updateContent = null;
- if (info instanceof ApkUpgradeInfo) {
- ApkUpgradeInfo upgradeInfo = (ApkUpgradeInfo) info;
- //Display update pop-up window.
- client.showUpdateDialog(this, upgradeInfo, false);
- updateContent = upgradeInfo.toString();
- Log.e(TAG, "onUpdateInfo status: " + status + ",failcause: " + rtnCode + ",isExit: "
- + isExit + ",updateInfo: " + info.toString());
- }
- }
- }
- public void onMarketInstallInfo (Intent intent){
- //Reserved method. No processing is needed.
- }
- public void onMarketStoreError ( int responseCode){
- //Reserved method. No processing is needed.
- }
- public void onUpdateStoreError ( int responseCode){
- //Reserved method. No processing is needed.
- }
- }
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 name | Parameter description |
| mContext | Context of the app client. |
| info | Detected update information. For details, see ApkUpgradeInfo. |
| mustBtnOne | Buttons 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. |
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.