About Android software updates

Source: Internet
Author: User

Let's briefly talk about software updates.

First, you must determine whether to update the software. To update an object, you must obtain the updated link. We can regard this as a simple system. The client request must correspond to the server. For the sake of simplicity, we put only one simple XML file on the server. The XML file contains the latest client version number (the version number is used here as much as possible, because the version number is int type for ease of comparison) and the latest APK version.

1 <update>
2 <version>2</version>
3 <url>http://www.youdoman.com/apk.apk</url>
4 </update>

This is a simple server.

The client only needs to read this XML and parse it through sax. Then obtain the Client Version Number and compare it with the latest version number read on the network. If the client version number is different from the server version number, update it. Call the system intent to download and update the APK.

1 // obtain the software system version number
2 public class appstatus {
3 protected static int getappversionid (context CTX ){
4 try {
5 return CTX. getpackagemanager (). getpackageinfo (CTX. getpackagename (), 0). versioncode;
6} catch (namenotfoundexception e ){
7 // todo auto-generated Catch Block
8 return-1;
9}
10}
11}

Sometimes, we may need to obtain some data from the mobile phone system to select the corresponding update data or collect statistics. The more data we get, the more favorable we will provide users with more accurate update options.

1 public class phonestatus {
2 // obtain the IMEI number of the mobile phone
3 protected string getimei (context CTX ){
4 telephonymanager = (telephonymanager) CTX. getsystemservice (context. telephony_service );
5 return telephonymanager. getdeviceid ();
6}
7 // obtain the mobile phone model
8 protected string GetModel (context CTX ){
9 return Android. OS. Build. model;
10}
11 // obtain the system firmware version
12 protected string gettarget (context CTX ){
13 return Android. OS. Build. version. release;
14}
15 // obtain the system firmware version
16 protected string getsdk (context CTX ){
17 return Android. OS. Build. version. SDK;
18}
19}

Once we get the data, we only need to hand it over to the server. The server can determine the returned data information through detailed information judgment. After obtaining the URL of the new APK version, you can use the system intent to download and install the APK.

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.