update升级包版本信息的读取

android设备在用U盘升级的时候,要先判断U盘中的升级包是否匹配此机型,是否高于当前版本。如果这些都成立的话,那么才刷机。这里我列出一个读取U盘版本信息的例子,只要运用了ZipInputStream  ZipEntry 。 

  public String getUdiskVersion() {

  1. Log.e(TAG, "--> getUdiskVersion()");  
  2. String zipFile = "mnt/udisk/usb/USB_DISK0/udisk0/update.zip";  
  3. File f = new File(zipFile) ;  
  4. if(!f.exists()){  
  5.     return "" ;  
  6. }  
  7. FileInputStream fis = null;  
  8. try {  
  9.     fis = new FileInputStream(f);  
  10. catch (FileNotFoundException e1) {  
  11.     // TODO Auto-generated catch block  
  12.     e1.printStackTrace();  
  13. }  
  14. BufferedReader reader = null;  
  15. String str = "";  
  16. String version = "";  
  17. ZipEntry ze = null;  
  18. ZipInputStream zis = null;  
  19.   
  20. try {  
  21.     zis = new ZipInputStream(fis);  
  22.     while ((ze = zis.getNextEntry()) != null) {  
  23.         if (ze.getName().equals("system/build.prop")) {  
  24.             Log.e(TAG, "找到了" + "路径是:" + ze.getName());  
  25.             break;  
  26.         }  
  27.     }  
  28.       
  29.     reader = new BufferedReader(new InputStreamReader(zis, "GBK"));  
  30.     while ((str = reader.readLine()) != null) {  
  31.         if (str.startsWith("ro.product.model")) {  
  32.             version = str.substring(str.indexOf('=') + 1);  
  33.             Toast.makeText(this, version, 0);  
  34.             Log.e(TAG, "--> str = " + str);  
  35.         }  
  36.     }  
  37. catch (IOException e) {  
  38.     e.printStackTrace();  
  39. finally {  
  40.     try {  
  41.         reader.close();  
  42.         ze.clone();  
  43.         zis.close();  
  44.         fis.close();  
  45.     } catch (IOException e) {  
  46.         e.printStackTrace();  
  47.     }  
  48. }  
  49. return version;  

转载自:http://www.verydemo.com/demo_c89_i41744.html
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值