【发布时间】:2014-04-01 15:23:42
【问题描述】:
我正在尝试从网站获取 JSON 格式的文本。它在我真正的智能手机上完美运行,但在 Android Emulator(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);
【问题讨论】:
-
你能发布更多与网址相关的代码吗?
标签: android json httpclient httpresponse