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!