android设备在用U盘升级的时候,要先判断U盘中的升级包是否匹配此机型,是否高于当前版本。如果这些都成立的话,那么才刷机。这里我列出一个读取U盘版本信息的例子,只要运用了ZipInputStream ZipEntry 。
public String getUdiskVersion() {
Log.e(TAG, "--> getUdiskVersion()");
String zipFile = "mnt/udisk/usb/USB_DISK0/udisk0/update.zip";
File f = new File(zipFile) ;
if(!f.exists()){
return "" ;
}
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedReader reader = null;
String str = "";
String version = "";
ZipEntry ze = null;
ZipInputStream zis = null;
try {
zis = new ZipInputStream(fis);
while ((ze = zis.getNextEntry()) != null) {
if (ze.getName().equals("system/build.prop")) {
Log.e(TAG, "找到了" + "路径是:" + ze.getName());
break;
}
}
reader = new BufferedReader(new InputStreamReader(zis, "GBK"));
while ((str = reader.readLine()) != null) {
if (str.startsWith("ro.product.model")) {
version = str.substring(str.indexOf('=') + 1);
Toast.makeText(this, version, 0);
Log.e(TAG, "--> str = " + str);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
ze.clone();
zis.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return version;
}