【问题标题】:Android emulator internet connection issues - real device works.Android 模拟器互联网连接问题 - 真实设备工作。
【发布时间】: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


【解决方案1】:

阅读本文,它应该可以解决您的问题:

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

【讨论】:

  • thx 输入 "-avd -dns-server 8.8.8.8" 解决了我的问题!
猜你喜欢
  • 1970-01-01
  • 2019-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-20
  • 2011-06-21
  • 1970-01-01
  • 2011-11-12
相关资源
最近更新 更多