Using HttpGet on Android

人走茶凉 提交于 2019-12-04 21:13:20

This is just a guess, but maybe this is because you are running the request on the main thread? You should usually prepare a background thread that will run this code for you.

The code looks approximately like this:

Runnable r = new Runnable() { 
  void run()
  {
       // enter here httpget code
  }
}

new Handler().post(r);

Did you added permission "android.permission.INTERNET" to your AndroidManifest.xml?

I found out, that this is a common problem, when there is no internet on emulator. I solved my problem by typing -http-proxy xxx.xx.111.1:3128 in Run->Run Configurations->Target->Additional Command Line Options(which is at the bottom, need to scroll). This is where I found a solution: http://www.gitshah.com/2011/02/android-fixing-no-internet-connection.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!