I´m trying to get a JSON-Format text from a website. It works perfectly on my real smartphone, but it don´t works in the 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.