This topic describes how to add the Upgrade SDK related to the release management. After adding the SDK and complete the necessary configurations, you can release a new version of an App is released in the mPaaS console, and the client can detect the new version through the upgrade API and remind users to download and upgrade.
Currently, Upgrade SDK supports access through Native AAR and Portal & Bundle.
The complete access process mainly includes the following 4 steps:
Initialize mPaaS(only required for Native AAR)
Prerequisites
If you access MDS through Native AAR, ensure that you have added mPaaS to project.
If you access MDS in componentized access mode (through Portal & Bundle projects), ensure that you have completed the componentized access process.
Add SDK
Native AAR mode
Follow the instructions in AAR component management to install the UPGRADE component in the project through Component management (AAR).
Componentized access mode
Install the UPGRADE component in the Portal and Bundle projects through Component management (AAR).
For more information, see Manage component dependencies > Add/delete component dependencies.
Configure project
Configure AndroidManifest
Add the following permissions in the
AndroidManifest.xml
file.<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Add the following configuration in the
AndroidManifest.xml
file:<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 the configuration of
AndroidManifest.xml
, please see App Manifest Overview.Create the
file_paths.xml
file in thesrc/main/res/xml
directory in the main module of the Portal project 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>
Add resources
If you access the UPGRADE SDK through Native AAR, you need to add the following resources to your App, otherwise, the upgrade component will not work. Click here to get the resource file.
Merge the content of strings.xml
, styles.xml
, and colors.xml
under the values
directory.
Initialize mPaaS
If you access the UPGRADE SDK through Native AAR you must initialize mPaaS.
Add the following codes in the object Application
:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// mPaaS initialization
MP.init(this);
}
}
For more details, see Initialize mPaaS.
Check for update
Quickly check for an update, and only the checking result is returned.
MPUpgrade mMPUpgrade = new MPUpgrade();
// The synchronization method, which is called in a subthread.
int result = mMPUpgrade.fastCheckHasNewVersion();
if (result == UpgradeConstants.HAS_NEW_VERSION) {
// New version available
} else if (result == UpgradeConstants.HAS_NO_NEW_VERSION) {
// No new version available
} else if (result == UpgradeConstants.HAS_SOME_ERROR) {
// Error
}