Android模拟器互联网连接问题 - 真正的设备工作。

时间:2014-04-01 15:23:42

标签: android json httpclient httpresponse

我正在尝试从网站上获取JSON格式的文本。它在我的真实智能手机上运行得很好,但在Android模拟器(4.0.3)中无效。 检查Internet连接是否正确:

ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected())
            return true;
        else
            return false;

这让我在我的模拟器中得到了空洞的结果,但我的手机中有一些东西:

HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));

    inputStream = httpResponse.getEntity().getContent();
        if (inputStream != null)
            result = convertInputStreamToString(inputStream);

1 个答案:

答案 0 :(得分:1)

通读这个,它应该可以解决你的问题:

http://www.gitshah.com/2011/02/android-fixing-no-internet-connection.html