本人目前在做MSM8909 OTA下载的应用,使用的是高通自带的QRDupdate.apk,搭建好服务器,写了xml配置文件。主要代码如下:
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<update>
<version>v2.0</version>
<file>update.zip</file>
<description>v2.0</description>
<delta>
<from>1</from>
<to>2</to>
</delta>
</update>
主要代码:
package com.qualcomm.update;
import java.io.Serializable;
public class UpdateInfo implements Serializable {
static class Delta implements Serializable {
private static final long serialVersionUID = 1L;
int from;
int to;
}
private static final long serialVersionUID = 1L;
public static final String QNAME_UPDATE = "update";
public static final String QNAME_VERSION = "version";
public static final String QNAME_FILE = "file";
public static final String QNAME_DES = "description";
public static final String QNAME_DELTA = "delta";
private String version;
private String fileName;
private String description;
private long size;
private Delta delta;
public Delta getDelta() {
return delta;
}
public void setDelta(Delta delta) {
this.delta = delta;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String toString() {
return "version:" + version + "\tfileName:" + fileName;
}
}
----------------------------------------------------------------------
package com.qualcomm.update;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.qualcomm.update.UpdateInfo.Delta;
public class UpdateInfoHandler extends DefaultHandler {
private List<UpdateInfo> updates;
private UpdateInfo info;
public void endElement(String uri, String localName, String qName) throws SAXException {
if (UpdateInfo.QNAME_UPDATE.equals(qName)) {
updates.add(info);
}
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (UpdateInfo.QNAME_UPDATE.equals(qName)) {
info = new UpdateInfo();
}
if (UpdateInfo.QNAME_VERSION.equals(qName))
info.setVersion(attributes.getValue("data"));
else if (UpdateInfo.QNAME_FILE.equals(qName))
info.setFileName(attributes.getValue("data"));
else if (UpdateInfo.QNAME_DES.equals(qName))
info.setDescription(attributes.getValue("data"));
else if (UpdateInfo.QNAME_DELTA.equals(qName)) {
Delta delta = new Delta();
try {
delta.from = Integer.parseInt(attributes.getValue("from"));
delta.to = Integer.parseInt(attributes.getValue("to"));
} catch (Exception e) {
return;
}
info.setDelta(delta);
}
}
public void startDocument() throws SAXException {
updates = new ArrayList<UpdateInfo>();
}
public List<UpdateInfo> getUpdates() {
return updates;
}
}
----------------------------------------------------------
运行之后发现,应用显示文件的大小是-1 bytes,并不是我想要升级的文件的大小,用Logcat抓取了一下log,发现getValue返回的值是null,请问有大牛知道这是什么原因吗?
|