首页 新闻 会员 周边

安卓4.0版本的app如何从服务器端获取js文件中的数据?

0
悬赏园豆:100 [已解决问题] 解决于 2014-02-10 19:23
 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;
            }
View Code

代码如上所示,将版本改为2.2可以获取到数据,改为4.0获取不到。怎么改才能使4.0能获取到服务器的数据?T T。有哪位大神知道~~急急急~~

时光未曾老去.的主页 时光未曾老去. | 初学一级 | 园豆:7
提问于:2014-01-25 17:15
< >
分享
最佳答案
1

只能用线程方式获取

收获园豆:100
glory.xu | 菜鸟二级 |园豆:302 | 2014-01-26 17:08

函数写在线程里,然后通过线程获取数据

可以通过Handler获取消息来更新当前页界面

glory.xu | 园豆:302 (菜鸟二级) | 2014-01-26 17:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册