public boolean getServerVer(){ try { String path=getResources().getString(R.string.url_server); URL url = new URL(path); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); //httpConnection.setDoInput(true); //httpConnection.setDoOutput(true); //httpConnection.setRequestProperty("Content-type", "application/x-java-serialized-object"); httpConnection.setRequestMethod("GET"); httpConnection.connect(); InputStream inputStream = httpConnection.getInputStream(); InputStreamReader reader = new InputStreamReader(inputStream); BufferedReader bReader = new BufferedReader(reader); String json = bReader.readLine(); JSONArray array = new JSONArray(json); JSONObject jsonObj = array.getJSONObject(0); newVerCode = Integer.parseInt(jsonObj.getString("verCode")); newVerName = jsonObj.getString("verName"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return true;//如果这里改为false 则不更新会退出程序 } return true; }
代码如上所示,将版本改为2.2可以获取到数据,改为4.0获取不到。怎么改才能使4.0能获取到服务器的数据?T T。有哪位大神知道~~急急急~~
只能用线程方式获取
函数写在线程里,然后通过线程获取数据
可以通过Handler获取消息来更新当前页界面