Android umeng incremental update and android incremental

Source: Internet
Author: User

Android umeng incremental update and android incremental

1. incremental upgrade Principle 
The principle of incremental update is to compare the local apk with the latest version on the server side and get the difference package. For example, the current version is 1.1.4, the size is 7.2 M, and the new version is 1.1.5. The size is 7.3 M. We found that the differences between the two versions are only 0.1M, so if we use incremental upgrades to generate a difference package of about 0.1M, in this way, you only need to download the M differential package for upgrade, instead of downloading the latest version of 7.3M.

2. Previous incremental upgrade implementation 
First, the server must generate the difference package. In this step, bsdiff (Binary difference tool) is used to generate the difference package for the old version and the new version, and then the application is provided to download the difference package. The application end encapsulates bspatch into the so dynamic library, and calls the dynamic library through jni to combine the old apk version and the difference package into the new apk version.

3. disadvantages of incremental upgrade in the past 
1. functions must be implemented on both the server and client, and the duration is long.
2. Users cannot upgrade to the latest version in a timely manner. Therefore, it is difficult to maintain a different package between each released version and the latest version.
3. when the client downloads the differential package generated by the server for merging, the merging may fail. This may be because the differential package generated by the server is incorrect, or the client merging may be faulty, A large number of tests and joint debugging are required.

4. umeng upgrade

4.1 import the jar package required by the SDK 
Download the zip package of the latest SDK, and merge the libs folder into the local project libs subdirectory. The libs/armeabi/libbspatch. so file in the libs directory is a library file that supports the incremental update function. You must also add it to eclipse.

4.2 Add a resource file 
Upload the res folder provided by the SDK to the project directory and merge it with the res directory of the project. Do not delete any files.

4.3 configure AndroidManifest. xml 
4.3.1 Add the permissions required by the SDK to the tag:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission><uses-permission android:name="android.permission.INTERNET"></uses-permission>

4.3.2 Add the APPKEY and channel to the tag: (if you have integrated the statistics SDK and other services of umeng, you do not need to add the APPKEY again)

<meta-data android:value="YOUR APP KEY" android:name="UMENG_APPKEY"/><meta-data android:value="Channel ID" android:name="UMENG_CHANNEL"/>

UMENG_APPKEY: used to locate the uniqueness of the application. Use the umeng appkey of YOUR application to replace "your app key" in the value ".
UMENG_CHANNEL: used to mark application promotion channels. Different channels can upload different update packages. You can use English letters and numbers of up to 20 digits as Channel names and replace "Channel ID" in value ". If this parameter is not changed, it indicates the default channel. To use umeng to automatically update multi-channel updates, you must first integrate the umeng statistics SDK.
4.3.3 add Service and Activity to the tag: (Note: In SDK v2.4, the dialog box is changed to Activity implementation, com. the umeng package name may change. If the package cannot be downloaded, check the package name and replace it with the correct package name)

<service    android:name="com.umeng.update.net.DownloadingService"    android:process=":DownloadingService" ></service><activity     android:name="com.umeng.update.UpdateDialogActivity"    android:theme="@android:style/Theme.Translucent.NoTitleBar" ></activity>

4.3.4 call the update Interface
Main application scenarios: The most common automatic update mode. When a user enters the application homepage, if the user is in a wifi environment, the system checks for updates. If there are any updates, a dialog box is displayed, prompting that a new version is available, click Update to download updates.
Call the OnCreate () method in the application entry Activity

public void onCreate(Bundle  savedInstanceState) {    super.onCreate(savedInstanceState);    UmengUpdateAgent.update(this);

Currently, automatic reminders are triggered only when Wi-Fi access is enabled. If you need to update automatically in any network environment, add the following code before calling update: UmengUpdateAgent. setUpdateOnlyWifi (false ).

4.4 upload the latest APK 
If the developer already has the latest APK version, you only need to upload it to the umeng website, and the Client Version Number (VersionCode) is smaller than the latest version, the client will receive an update prompt when it starts.

5. umeng update scenario 
5.1 automatic update
The most common automatic update mode: when a user enters the application homepage, an update is automatically detected if the user is in the wifi environment (only in the wifi environment by default, for the sake of user traffic. This behavior can be changed). If there is an update, the pop-up dialog box prompts that there is a new version. You can click Update to start downloading the update.
Call the OnCreate () method in the application entry Activity

public void onCreate(Bundle  savedInstanceState) {    super.onCreate(savedInstanceState);    UmengUpdateAgent.update(this)    //UmengUpdateAgent.update(this, "appkey", "channel");

5.2 manual update
Main application scenarios: Many application configuration interfaces have similar functions, such as checking for updates. You need to trigger the updates to detect updates. Its default behavior is basically the same as that of automatic updates.
The main difference between automatic update and manual update is that, in this case, regardless of network conditions, whether or not the user has ignored updates of this version, you can initiate an update check in the callback of the button as shown in the following example, instead of update (Context context ):

public void onClick(View v) {    UmengUpdateAgent.forceUpdate(mContext);}

5.3 silent download and update
Main application scenarios: when a user enters the application homepage, if the user is in the wifi environment for detection and update, if there is an update, the new version is downloaded in the background. If the download is successful, the notification bar is displayed. the user clicks the notification bar to start the installation.
If wifi is disconnected during silent download, the download will stop.
Call the OnCreate () method in the application entry Activity

public void onCreate(Bundle  savedInstanceState) {    super.onCreate(savedInstanceState);    UmengUpdateAgent.silentUpdate(this);

6. umeng incremental upgrade 
The principle of umeng incremental update is: after the application is integrated with umeng to automatically update the SDK, the SDK will send the Version Code of the mobile phone and the MD5 value of the application APK file to umeng's server at app startup. The server finds the old APK version based on the MD5 value, performs diff with the new and old APK versions, generates a patch file, and returns it to the SDK. The SDK then combines the patch file with the old APK file on the mobile phone to generate the new APK. The MD5 value of the new APK file generated by the mobile phone end will be strictly consistent with the MD5 value of the new APK file on the server end. In this process, the umeng server must have the new and old versions of APK files.
Umeng uses incremental updates by default. If you want to use full updates, you can call setDeltaUpdate (boolean deltaUpdate). The default value is true. If it is set to false, it indicates full updates.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.