Quick start

更新时间:
复制 MD 格式

Add the Upgrade SDK to enable release management in your app. Once integrated, you can publish a new version from the mPaaS console, and the client automatically detects it through the upgrade API and prompts users to download and install the update.

The Upgrade SDK supports two integration methods: Native AAR (Android Archive) and Component-based.

Follow these four steps to complete the integration:

  1. Add SDK

  2. Configure project

  3. Initialize mPaaS (only for native AAR integration)

  4. Check for upgrades

Prerequisites

Add SDK

Native AAR method

In your project, use Component Management (AAR) to install the UPGRADE component. For more information, see Manage component dependencies.

Component-based method

In the Portal and Bundle projects, use Component Management to install the UPGRADE component. For more information, see Add component dependencies.

Configure project

Configure AndroidManifest

  1. Add the following permission to your AndroidManifest.xml file:

     <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
  2. Add the following configuration to your AndroidManifest.xml file.

    Replace ${applicationId} with your actual package name. For example, replace ${applicationId}.fileprovider with com.mpaas.mobiledeliveryservice.fileprovider.

     <provider
     android:name="android.support.v4.content.FileProvider"
     android:authorities="${applicationId}.fileprovider"
     android:exported="false"
     android:grantUriPermissions="true">
     <meta-data
      android:name="android.support.FILE_PROVIDER_PATHS"
      android:resource="@xml/file_paths" />
     </provider>
    Note

    For more information about configuring AndroidManifest.xml, see App Manifest Overview.

  3. In the src/main/res/xml folder of your Portal project's main module, create a file named file_paths.xml with the following content:

     <?xml version="1.0" encoding="utf-8"?>
     <resources>
     <paths>
      <external-files-path
          name="download"
          path="com.alipay.android.phone.aliupgrade/downloads" />
      <external-path
          name="download_sdcard"
          path="ExtDataTunnel/files/com.alipay.android.phone.aliupgrade/downloads" />
     </paths>
     </resources>
    Note

    If your targetSdkVersion is greater than 24, you must add an additional configuration. For more information, see Default storage path.

Add resources

Note

This step applies to native AAR integration only. Without these resources, the Upgrade component will not work. Click here to download the resource files.

Merge the contents of strings.xml, styles.xml, and colors.xml into the corresponding files in the values folder.

Initialize mPaaS

This step applies to native AAR integration only.

Add the following code to your Application object. Call MP.init(this) in onCreate to ensure mPaaS initializes before any other app component starts:

public class MyApplication extends Application {
    
    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize mPaaS. Must be called before using any mPaaS SDK.
        MP.init(this);    
    }
}

For more information, see Initialize mPaaS.

Check for upgrades

Use fastCheckHasNewVersion() to check whether a new version is available. This is a synchronous method that returns only the check result — call it on a background thread:

MPUpgrade mMPUpgrade = new MPUpgrade();
// Synchronous method. Call it in a background thread.
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 occurred.
}