简体   繁体   English

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

[英]Android emulator internet connection issues - real device works.

I´m trying to get a JSON-Format text from a website. 我正在尝试从网站获取JSON格式的文本。 It works perfectly on my real smartphone, but it don´t works in the Android Emulator(4.0.3). 它可以在我真正的智能手机上完美运行,但不能在Android Emulator(4.0.3)中运行。 Checking Internet Connection is positive with this one: 检查互联网连接是否正常:

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

That gives me empty result in my emulator, but I get something in my phone: 这给我的模拟器一个空的结果,但是我在手机中得到了一些东西:

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

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

Read through this, it should solve your problem: 通读此书,它应该可以解决您的问题:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android应用在模拟器上工作正常,但在设备上无效。 使用Internet连接 - Android app works fine on Emulator, but not on Device. Uses Internet Connection 我的Android应用程序无法在模拟器上访问Internet,但在真实设备上可以正常工作 - My android application not able to access internet on emulator but works fine on real device Android应用程序可以在模拟器中正常运行,但不能在真实设备中运行? - Android application works fine in emulator but not in real device? 适用于 Android 模拟器的 Socket 有效但不适用于真实设备 - Socket For Android Emulator Works but Not For Real Device Android应用程序可以在模拟器上正常运行,但不能在真实设备上运行 - Android Application works fine on emulator but not on a real device Android Studio 应用程序可以在模拟器中运行,但不能在真实设备上运行 - Android Studio app works in emulator but not on a real device Android小部件仅在模拟器上有效,而不能在真实设备上有效 - Android widget works only on emulator not on real device Android App可在模拟器上运行,但不能在真实设备上运行 - Android App works on emulator, but not on real device React Native 适用于真实设备,但不适用于 android 模拟器 - React Native works with a real device but not with an android emulator android 应用程序适用于模拟器但不适用于真实设备 - android app works on emulator but not in real device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM