目录

AppUpdateClient

Interface Info

public interface AppUpdateClient

Provides methods related to app updates. An AppUpdateClient instance is returned when JosApps.getAppUpdateClient is called.

Public Method Summary

Qualifier and Type

Method Name and Description

void

checkAppUpdate(Context context, CheckUpdateCallBack callBack)

Checks for app updates.

void

showUpdateDialog(Context context, ApkUpgradeInfo info,boolean mustBtnOne)

Displays a pop-up prompting app update.

void

releaseCallBack()

Releases callback.

Public Methods

[h2]checkAppUpdate

Method

public void checkAppUpdate(Context context, CheckUpdateCallBack callBack)

Checks for app updates after the app is launched and initialized or a user proactively checks for update on the app.

Parameters

Name

Description

context

Client context.

callBack

Callback result for checking for app updates. The CheckUpdateCallBack object is defined as follows:

public interface CheckUpdateCallBack {
      // Status update information obtained from AppGallery.
      // Refer to intent to see parameters.
       void onUpdateInfo(Intent intent);
         // The following method is reserved. No handling is required. 
       void onMarketInstallInfo(Intent intent);
       // The following method is reserved. No handling is required. 
       void onMarketStoreError(int responseCode);
       // The following method is reserved. No handling is required. 
       void onUpdateStoreError(int responseCode);
   }

intent

Parameter

How to Obtain

Type

Description

status

intent.getIntExtra(UpdateKey.STATUS, DEFAULT_VALUE)

Note: DEFAULT_VALUE is the custom default value used 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 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 an app update is available.
  • 8: constant value MARKET_FORBID, indicating that 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 used 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 if your app or game enables forcible updates. 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 used when the value of UpdateKey.BUTTON_STATUS cannot be obtained.

int

Indicates whether the user chooses to update your app or game immediately or later if your app or game does not enable forcible updates. The options are as follows:

  • 100: Delayed update. The user can continue using the app or game.
  • 101: Immediate update.

info

intent.getSerializableExtra(UpdateKey.INFO)

Serializable

App update information. For details, please refer to ApkUpgradeInfo.

Sample Code

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, 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 the update pop-up. 
                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 handling is required. 
     }
     public void onMarketStoreError ( int responseCode){
            // Reserved method. No handling is required. 
     }
     public void onUpdateStoreError ( int responseCode){
            // Reserved method. No handling is required. 
     }
}

[h2]showUpdateDialog

Method

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

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

Parameters

Name

Description

context

Client context.

info

Detected update information. For details, please refer to ApkUpgradeInfo.

mustBtnOne

Indicates whether forcible update is required for a user. 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.

[h2]releaseCallBack

Method

public void releaseCallBack()

Releases callback to prevent memory leaks. You need to call this method in destroy. For methods of static internal classes, this method does not need to be called.