Use umeng to automatically update apk and umeng apk
[Statement]
Reprinted, but keep the original source of the article → _ →
Life One: http://www.cnblogs.com/smyhvae/
Source: http://www.cnblogs.com/smyhvae/p/4653736.html
Contact: smyhvae@163.com
1. Download the SDK:Link to the official website: Download, click the red box to download the SDK.
2. register an application in the background of umeng:Click the red box to create a new application. .
2. Configure in the Code:Now start to see how the official documentation, documentation links are as follows: http://dev.umeng.com/auto-update/android-doc/quick-start
1. Import the jar package required by the SDK:Merge the libs folder in the SDK to the local project libs subdirectory.
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. Tip: The resource files provided by umeng SDK start with umeng.
3. Configure AndroidManifest. xml:3.1 open AndroidManifest. xml and add the permissions required by the SDK to the <manifest> label:
1 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>2 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>3 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
In the code above: the first row of permission allows you to save the downloaded apk to the SD card. The permission in the second row is to allow you to check the network status and decide the download policy based on different network environments. You must add this permission.
3.2. Next, add the APPKEY and channel to the <application> tag: (if you have already 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, the default channel is used. (Note: To use umeng to automatically update multi-channel updates, you must first integrate the umeng statistics SDK.) 3.3. Add the Service and Activity to the <application> tab:
<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. Call the update interface:Main application scenarios: The most common is
Automatic updateMode: After you enter the application homepage, update is detected if you are in the wifi environment. If there is an update, a dialog box is displayed, prompting you to click Update to download the update. Call the following code in the OnCreate () method of the application entry Activity:
1 public void onCreate(Bundle savedInstanceState) {2 super.onCreate(savedInstanceState);3 UmengUpdateAgent.update(this);
That is, you can call the 3rd lines of code above.
Note: Considering the user traffic restrictions, we will automatically remind you when using Wi-Fi access by default. If you need to update automatically in any network environment, add the following code before calling update: UmengUpdateAgent. setUpdateOnlyWifi (false ). Note: For devices that may not support or do not have a wireless network, add the above Code as well.
5. Integrated Monitoring:The integration detection function is enabled by default in SDK Versions later than v2.4. After any updated interface is called, we will automatically check whether steps 2 and 3 in the above integration process are completed correctly for you. If it is completed correctly, no prompt will appear. Otherwise, the following toast will prompt you. You can disable this function by calling UmengUpdateAgent. setUpdateCheckConfig (false. The meaning of toast is as follows: "Please copy all resources (res/) from SDK to your project! ": Check whether all resource files in the res folder are stored in the project. "Please add Permission in AndroidManifest! ": Check whether the related permissions in Step 1.3 are correctly added. "Please add Activity in AndroidManifest! ": Check whether Activity 1.3 in Step 3.3 is correctly added. "Please add Service in AndroidManifest! ": Check whether the Service in Step 1.3 is correctly added. "Please set umeng appkey! ": Check whether the APPKEY in Step 3.2 is correctly added.
3. Upload the latest apk for updates:Assume that the previous version number is 1.0. If you have developed a new version, you only need to upload it to umeng website and the new version number (VersionCode) must be later than 1.0, when the client is started, an update prompt is displayed. Let's experiment. Click "component" in the red box, and then click "Auto Update" in the red box. A text prompt is displayed. Note the text in the blue box. Let's first modify the code in the project file and change the text content of TextView to "hulara, I am the second version ". Then
Modify the gradle file in the module of the app to increase the version number.. As shown in:, update the version number in the red box. Note that the versionCode of row 11th must be an integer. Then generate the new apk. Then open umeng's background:, upload the new apk, and fill in the Update log. Click "OK" to bring up the following interface:
Iv. test:The following interface is displayed after the apk of v1.0 is run: After the automatic update function is added, open the program. The following interface is displayed: after the update, the results are as follows:
Note: If you click Update, the following interface is displayed: the error is caused by different signatures used for the two versions of apk. Also recommend a connection to look at: umeng automatically update FAQ index (developer must read) http://bbs.umeng.com/thread-5924-1-1.html [project files] 2015-07-16-UpdateDemo project files