Application update implementation of Android development

Source: Internet
Author: User

Recently to upgrade the Project app, a little research on Android app updates, share my experience.

Since it is an update, it must be networked and downloaded, so there must be networking and storage access:

<!--permission Request--
<uses-permission android:name= "Android.permission.INTERNET"/><!--networking Privileges--
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/><!--storage Privileges--
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

Can be used in XML and database, PHP and other ways to detect the upgrade version

Xml:

<?xml version= "1.0" encoding= "Utf-8"?>
<update>
<version>2.0<ersion>
<description> here to write some features of this version </description>
<apkurl> fill out the app download </apkurl>
<!--Here's the IP address be sure to write the IP address of the computer where your server is located, we will place a new.apk in the security directory, to update the
</update>

Match:

public class Updateinfoparser {
public static UpdateInfo Getupdateinfo (InputStream is) throws Exception {
UpdateInfo info = new UpdateInfo ();
Xmlpullparser Xmlpullparser = Xml.newpullparser ();
Xmlpullparser.setinput (IS, "utf-8");
int type = Xmlpullparser.geteventtype ();
while (type! = xmlpullparser.end_document) {
Switch (type) {
Case Xmlpullparser.start_tag:
if (Xmlpullparser.getname (). Equals ("version")) {
Info.setversion (Xmlpullparser.nexttext ());
} else if (Xmlpullparser.getname (). Equals ("description")) {
Info.setdescription (Xmlpullparser.nexttext ());
} else if (Xmlpullparser.getname (). Equals ("Apkurl")) {
Info.seturl (Xmlpullparser.nexttext ());
}
Break
Default
Break
}
Type = Xmlpullparser.next ();
}
return info;
}
}

HTTP request:

public class Updateinfoservice {
Private context context;

Public Updateinfoservice (Context context) {
This.context = context;
}

Public UpdateInfo getupdateinfo (int urlId) throws Exception {
String path = Context.getresources (). getString (urlId);//Get the address stored in config.
URL url = new URL (path);
HttpURLConnection httpurlconnection = (httpurlconnection) url.openconnection ();//Open an HTTP link
Httpurlconnection.setconnecttimeout (5000);//Set the time-out for the link, now 5 seconds
Httpurlconnection.setrequestmethod ("GET");//How to set the request
InputStream is = Httpurlconnection.getinputstream ();//get an input stream. It contains Update.xml's information.
Return Updateinfoparser.getupdateinfo (IS);//Parse XML
}
}

You can then compare and download updates based on the data you've acquired.

Other practices are similar to this one, but this is simpler and the most frequent way to use it.


Personal hard work results, if reproduced, please indicate the source, thank you!

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.