All Products
Search
Document Center

Mobile Platform as a Service:Advanced operations

Last Updated:Feb 02, 2023

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:

MPLogger.setUserId("your whitelist ID");

Detect new version

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

    Note

    Only the upgrade popup is displayed quickly, and the forced upgrade logic is not included. If you need to force an upgrade, please use a custom upgrade to implement it.

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

      MPUpgrade mMPUpgrade = new MPUpgrade();
      // The synchronous method, which is called in the subthread.
      int result = mMPUpgrade.fastCheckHasNewVersion();
      if (result == UpgradeConstants.HAS_NEW_VERSION) {
          // A new version is available.
      } else if (result == UpgradeConstants.HAS_NO_NEW_VERSION) {
          // No new version is available.
      } else if (result == UpgradeConstants.HAS_SOME_ERROR) {
          // An error occurs.
      }

Obtain upgrade details

Call the fastGetClientUpgradeRes method to obtain more information.

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

The returned example displays information such as the new version number, download address, etc. Some of the parameters have the following meanings:

  • 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:

      MPUpgrade mMPUpgrade = new MPUpgrade();
      mMPUpgrade.setUpgradeCallback(new MPaaSCheckVersionService.MPaaSCheckCallBack() {
           .........
      });
  • 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:

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

Add the following configurations in the file_path.xml file:

// external-files-path corresponds to the directory of getExternalFilesDir
// 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
<external-files-path
    name="download"
    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.

     public class UpgradeForceExitCallbackImpl implements UpgradeForceExitCallback {
         @Override
         public boolean needForceExit(boolean forceExitApp, MicroApplicationContext context) {
             // 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.
             return false;
         }
         @Override
         public void doForceExit(boolean forceExitApp, MicroApplicationContext context) {
             // If you need to stop the process, ensure that the needForceExit method above returns true, and then stop the process in this method.
         }
     }
  2. Set the callback.

     MPUpgrade mpUpgrade = new MPUpgrade();
     mpUpgrade.setForceExitCallback(new UpgradeForceExitCallbackImpl());
      Important

      Use the same MPUpgrade instance to set a callback or request an upgrade.

      After setting the callback, you can avoid the failure of parsing the package, but the upgrade component will no longer automatically kill the process for you. Therefore, when the user does not click Install but returns to the application, please set an irrevocable pop-up cover layer by yourself to prevent the user from bypassing the forced upgrade.