Android(Java):http options

/**
  * 检测软件更新
  */
 public void checkUpdate(boolean showAlert, final View v) {
  if(!NetWorkUtil.isNetworkConnected(mContext)){
   new AlertDialog.Builder(mContext).setTitle("提示")
   .setMessage("网络异常,请稍后重试")
   .setPositiveButton("确定", null).show();
   v.setEnabled(true);
   return;
  }
  this.showAlert = showAlert;
  view = v;
  new Thread(){
   public void run(){
    // 获取当前软件版本
    double versionCode = getVersionCode(mContext);
    // 把version.xml放到网络上,然后获取文件信息
    // InputStream inStream =
    // ParseXmlService.class.getClassLoader().getResourceAsStream("version.xml");
    // 解析XML文件。 由于XML文件比较小,因此使用DOM方式进行解析
    ParseXmlService service = new ParseXmlService();
    try {
     URL url = new URL(path);
     HttpURLConnection conn = (HttpURLConnection) url.openConnection();
     conn.setRequestMethod("OPTIONS");
     conn.getResponseCode();
     conn = (HttpURLConnection) url.openConnection();
     conn.setReadTimeout(5 * 1000);
     conn.setRequestMethod("GET");
     InputStream inStream = conn.getInputStream();
     mHashMap = service.parseXml(inStream);
    } catch (Exception e) {
     mHandler.sendEmptyMessage(ERROR);
     Log.e(TAG, e.toString());
     //Toast.makeText(mContext, e.toString(), Toast.LENGTH_LONG).show();
    }
    if (null != mHashMap) {
     serviceCode = Double.valueOf(mHashMap.get("version"));
     name = mHashMap.get("name");
     enforceUpdate = Integer.valueOf(mHashMap.get("enforceUpdate"));
//     if(null!=mHashMap.get("mHashMap"))
//      minimumVersion = Integer.valueOf(mHashMap.get("minimumVersion"));
//      //忽略版本判断
//      if(minimumVersion==-1){
//       return false;
//      }else {
       // 版本判断
       if (serviceCode > versionCode) {
        mHandler.sendEmptyMessage(-1);
        return;
       }
       mHandler.sendEmptyMessage(0);
//      }
    }
     } 
  }.start();
 }

你可能感兴趣的:(http)