标签:android
try { URL url = new URL(getString(R.string.serverurl)); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); int code = conn.getResponseCode(); if (code == 200) { InputStream is = conn.getInputStream(); updateInfo = UpdateInfoParser.getUpdateInfos(is); if (updateInfo != null) { if (getVersion().equals(updateInfo.getVersion())) { // 版本号相同,进入应用程序主界面 msg.what = LOAD_MAIN_UI; } else { // 版本号不相同,提示用户更新应用程序 msg.what = SHOW_UPDATE_INFO; } } else { // 解析xml失败 msg.what = XML_PARSE_ERROR; } } else { // 服务器错误,资源没找到 msg.what = SERVER_ERROR; } } catch (MalformedURLException e) { e.printStackTrace(); msg.what = URL_ERROR; } catch (IOException e) { e.printStackTrace(); msg.what = NETWORK_ERROR; }
HttpUrlConntion inputstream,布布扣,bubuko.com
标签:android
原文地址:http://blog.csdn.net/feecooling/article/details/38492335