Here is a great helper method by MisterSquonk to detect if your app has an internet connection or not.

Note that this method cannot be used to check if an external site you are trying to access is alive or not.

It is common for developers who are new to Android to encounter problems with the emulator connecting to external websites. The first thing I did was to include the

tag in my AndroidManifest.xml file which, turned out not to be the solution since my app still could not access external websites. To confirm that your app is not the culprit for your internet connection woes, try to open the browser app of the emulator and surf to any well known sites like Google.

If it cannot access it, then the emulator does not have any connection at all. To make this work, try doing the following steps in your Eclipse IDE.

  • Go to Window > Preferences > Android > Launch
  • Under the default emulator options, add this -dns-server,

It worked for me.

I came upon this problem because the site I wanted to access had server problems, meaning the website was down. When my code tried to access it again, it gave out this “Invalid use of SingleClientConnManager: connection still allocated” exception message.

My code uses Apache’s HttpClient 3rd party library and I thought at first calling the consumeContent() method of the HttpEntity class did the trick since I never even closed the InputStream when getting a reference to it. It did not.

Luckily, after much surfing I stumbled upon Jason Hudgin’s site where he created a convenience method that avoids this problem.

Related Posts Plugin for WordPress, Blogger...