About Android software updates

Questions about software updates, a brief speech.

First you need to determine whether the software update needs to be updated. If you need to update, you need to get updated link. We can see this as a simple system. Need client requests and corresponding server. For simplicity we will end service to just put a simple XML file, XML file contains the latest client version number (here, as far as possible the version number because the version number is Int type of easy comparison) and the latest version of the APK Download .

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

Such a simple server-side on it.    

The client only needs to read this xml, and through the sax resolution. The latest version number and then get the client version numbers follow the network read comparison, if the client version number with the version number of different server needs to be updated, the system calls the Intent to download the updated APK.

 1 //获取软件系统版本号
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 get some data on the phone system used to select the appropriate update data or statistics some data. Get more data, the more beneficial to us to provide users with a more accurate update the selection.

 1 public class PhoneStatus {
2 //获取手机的IMEI号
3 protected String getImei(Context ctx){
4 TelephonyManager telephonyManager=(TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
5 return telephonyManager.getDeviceId();
6 }
7 //获得手机型号
8 protected String getModel(Context ctx) {
9 return android.os.Build.MODEL;
10 }
11 //获得系统固件版本
12 protected String getTarget(Context ctx) {
13 return android.os.Build.VERSION.RELEASE;
14 }
15 //获得系统固件版本号
16 protected String getSDK(Context ctx) {
17 return android.os.Build.VERSION.SDK;
18 }
19 }

As long as we get the data to the server, the server can be determined by detailed information to determine the returned data. The new version of the url get after apk can download and install APK through the system Intent.

Reproduced in: https: //my.oschina.net/weisenz/blog/200616

Guess you like

Origin blog.csdn.net/weixin_33830216/article/details/91920870