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:
Add SDK
Configure project
Initialize mPaaS (only for native AAR integration)
Check for upgrades
Prerequisites
For native AAR integration, first add mPaaS to your project.
For component-based integration, first complete the component-based integration process.
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
-
Add the following permission to your
AndroidManifest.xmlfile:<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> -
Add the following configuration to your
AndroidManifest.xmlfile.Replace
${applicationId}with your actual package name. For example, replace${applicationId}.fileproviderwithcom.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>NoteFor more information about configuring
AndroidManifest.xml, see App Manifest Overview. -
In the
src/main/res/xmlfolder of your Portal project's main module, create a file namedfile_paths.xmlwith 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>NoteIf your
targetSdkVersionis greater than 24, you must add an additional configuration. For more information, see Default storage path.
Add resources
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.
}