All Products
Document Center

Advanced operations

Last Updated: Mar 05, 2021

After integrating the SDK, you can set whitelist, use the SDK to detect upgrades and notify users of any upgrades based on business requirements.

Set whitelist

Set whitelist user ID:

  1. MPLogger.setUserId("your whitelist ID");

Detect new version

  • Detect new versions quickly and remind users with a pop-up:

    1. MPUpgrade mMPUpgrade = new MPUpgrade();
    2. mMPUpgrade.fastCheckNewVersion(activity, drawable);
  • Detect new versions quickly and return the detection result only:

    Note: The following code is used to show update reminder quickly, and it does not contain the logic to force an upgrade. If you want to force the upgrade, please use custom upgrade.
    1. MPUpgrade mMPUpgrade = new MPUpgrade();
    2. // The synchronous method, which is called in the subthread.
    3. int result = mMPUpgrade.fastCheckHasNewVersion();
    4. if (result == UpgradeConstants.HAS_NEW_VERSION) {
    5. // A new version is available.
    6. } else if (result == UpgradeConstants.HAS_NO_NEW_VERSION) {
    7. // No new version is available.
    8. } else if (result == UpgradeConstants.HAS_SOME_ERROR) {
    9. // An error occurs.
    10. }

Obtain upgrade details

Call the fastGetClientUpgradeRes method to obtain more information.

  1. MPUpgrade mMPUpgrade = new MPUpgrade();
  2. // The synchronization method, which is called in a subthread.
  3. ClientUpgradeRes clientUpgradeRes = mMPUpgrade.fastGetClientUpgradeRes();

In the following example, the information returned includes the new version number and download link:


Where, the meaning of some parameters are as follows:

  • downloadURL: Download address
  • guideMemo: Upgrade information
  • newestVersion: Latest version number
  • resultStatus: Upgrade mode
    • 202: Single reminder
    • 204: Multiple reminders
    • 203/206: Forced update

Other custom detections

For more information about custom detections, see the following example:

  • Implement the MPaaSCheckCallBack interface to respond to requests created by the upgrade SDK, such as displaying a pop-up:

    1. MPUpgrade mMPUpgrade = new MPUpgrade();
    2. mMPUpgrade.setUpgradeCallback(new MPaaSCheckVersionService.MPaaSCheckCallBack() {
    3. .........
    4. });
  • Call the MPUpgrade.checkNewVersion method to detect upgrades.

    Note: MPUpgrade encapsulates the call of MPaaSCheckVersionService. You can also customize the implementation method. For information about MPaaSCheckVersionService and MPaaSCheckCallBack, see API reference.

Customize the download directory of installation package (for 10.1.60 and later versions )

The configuration is as follows:

  1. File dir = getApplicationContext().getExternalFilesDir("Custom directory");
  2. MPUpgrade mpUpgrade = new MPUpgrade();
  3. mpUpgrade.setDownloadPath(dir.getAbsolutePath());

Add the following configurations in the file_path.xml file:

  1. // external-files-path corresponds to the directory of getExternalFilesDir
  2. // Use the element corresponding to your custom directory. If you are not sure about how to select an element, search for “Adapt FileProvider” on the Internet
  3. <external-files-path
  4. name="download"
  5. path="custom directory" />

Handle the SDK package parsing failure upon forced upgrade

Some ROMs may fail to parse the SDK package after forced upgrade. This is because the ROMs need to access the corresponding App process when installing the package. However, the App process will be forcibly stopped during forced upgrade. As a result, the package fails to be parsed. Although such custom ROM behavior is incompliant with the native Android platforms, you can still solve the problem by implementing UpgradeForceExitCallback to return false in needForceExit.

  1. Implement a callback.

    1. public class UpgradeForceExitCallbackImpl implements UpgradeForceExitCallback {
    2. @Override
    3. public boolean needForceExit(boolean forceExitApp, MicroApplicationContext context) {
    4. // If false is returned, the app process will not be forcibly stopped, and the installation package will be parsed successfully. If true is returned, you need to call the doForceExit method below to stop the process.
    5. return false;
    6. }
    7. @Override
    8. public void doForceExit(boolean forceExitApp, MicroApplicationContext context) {
    9. // If you need to stop the process, ensure that the needForceExit method above returns true, and then stop the process in this method.
    10. }
    11. }
  2. Set the callback.

    1. MPUpgrade mpUpgrade = new MPUpgrade();
    2. mpUpgrade.setForceExitCallback(new UpgradeForceExitCallbackImpl());
    • Use the same MPUpgrade instance to set the callback or request upgrade.
    • After setting the callback, the SDK package will not fail to be parsed, but the upgrade component will no longer automatically stop the process. Therefore, you need set a pop-up window overlay that cannot be closed by a user when the user returns to the App instead of tapping Install. In this way, the user is unable to skip any forced upgrade.