Saturday, February 19, 2011

Android - Fixing the no internet connection issue on emulator

Recently, while developing an Android Application, I was faced with a situation that wasted 2 hours of my time.  The issue was simple, my app was not able to access internet from the Android Emulator.

Initially I thought fixing the issue should have been straight forward, but life is not always that simple.

So what was the real issue because of which my app was not able to access internet?  There are multiple reasons because of which this issue could occur.  Hence, I decided to document my findings so that other could benefit from it.

There are two main symptoms of no internet connection on android emulator
  • Only your app is not able to access the internet
  • None of the apps are able to access the internet
Lets look at what are the reasons behind each of them.

Only your app is not able to access the internet

If only your app is not able to access the internet on the emulator, check if any other apps are able to access the internet or not.  For e.g. you could open up the browser application, visit  If the page opens up correctly then problem lies in your app itself and its simple to fix.

Basically, your app needs the Permission to access the internet.  This can be done by adding the following line just before the end of <manifest> tag in AndroidManifest.xml file of your application.

A sample AndroidManifest.xml file with the added permission would look like

Compile and re-install the app in the emulator and try to access the internet from your app. It should work!

What is the use of uses-permission tag:

Android application can request certain permissions so that they can function properly.  Some examples of permissions are, get users location, make a call, access the internet etc. App has to explicitly specify this in the AndroidManifest.xml.

When end users install such an app on their device, the android OS will notify the user that, app is requesting certain permissions.  If users are fine with that, then only the app will be installed.  Else users can deny the permission and the app will not be installed.

This mechanism is Androids way of implementing security and users privacy!

None of the apps are able to access the internet

Now this situation is tricky.  There are two reasons because of which this could happen
  • Proxy server is not configured on the emulator
  • Incorrect DNS used by the emulator

Configuring the proxy server on the emulator:

If you access internet via a proxy server, then you will need to configure the proxy server on the emulator as well.  This is done via the following steps.

Open up the Settings application on the Emulator 

Select the Wireless & Network settings
Wireless and Networks
Select the Mobile networks 
Mobile Networks
Select the Access Point Names
Access Point Names
Select the Access Point listed there.  In my case its Telkila
Select the access point
In the Edit access point section edit the value of Proxy and Port.  These should point to your Proxy server and Port that you use.
Set the proxy and port values
Thats it!  After doing these settings try to access the internet from the browser application on the emulator.  It should work!

If you are not behind a proxy (like me) then the problem is because of an incorrect dns server.  Lets look at how to fix the dns issue.

Incorrect DNS Used by the Emulator:

In my case none of the above things fixed the issue.  The real issue was that the DNS used by the Emulator was incorrect.  Fortunately there is a way in which we can specify which DNS server to use.  

Android Emulator takes a command line parameter -dns-server using which you can specify which DNS server to use.  The sample command to specify DNS server would look like

-dns-server takes a comma separated list of IP address to use as DNS server.

That did the trick for me!  I was finally able to access internet from my app on the android emulator!


  1. You are a total genius!

    I wasted more than two hours trying to figure out why i could only access our 'safe sites' on the emulator's browser, and changing proxies in the eclipse option.
    Never did i think that it should be changed in the emulator device itself.
    thanks you.

  2. Hi,

    I am glad the post helped you.

    Thanks & Regards

    Deep Shah

  3. thanks, it helped me to find a correct direction to fix my issue.

  4. c:\>emulator.exe -avd Android1.6 -dns-server
    DNS server '' resolve to ''
    ###warning: could not add DNS server to network stack
    ###warning: will use system default DNS server

  5. Hello Jeet,

    There are multiple reasons because of which the warning messages you are seeing could appear. Try using the Googles public DNS server does this help?

    emulator.exe -avd Android1.6 -dns-server

    Also tell me which OS are you using? WindowsXP?

  6. Hi,

    Worked for me by setting the DNS server to and then taking care of setting the proxy host using an IP address instead of a name (otherwise the emulator will try to resolve your proxy's IP address using the public DNS, which will fail when your proxy is private)

    Thanks for the help

  7. Hi Deep and Jeet, thanks I got the same issue and also wasted 2 hours of my time! But thanks to your help and I've set the DNS to and it worked!

  8. Dennis,

    Glad that it worked out for you.


    You are welcome.


    Deep Shah

  9. I have been facing the same problem as mentioned...but in my case...the emulator goes to a not responding crashes...i have tried the above solutions

  10. I have also tried reinstalling android sdk eclipse and plugins

  11. windows 7

  12. Hello Avinash,

    Need more information on whats happening with your emulator. Does it crash when you open up your app?

    Does it crash on opening any application?

    Can you check if you can open up a browser and visit on it?

    Try to narrow down the problem. Is the problem in your app or in the emulator/machine configuration?

  13. Problem:
    Emulator crashes when i run my application which requires the connection to the internet...opening a browser it also not responding state...
    I reinstalled everything on a windows xp platform,it works fine now.

    After a few days tried it again on my laptop(Windows 7)setting it to the google dns,it i have to do this everytime i start the emulator,then after making changes i run it from eclipse and it connects,thanks...

  14. very nice post. i like how pretty much all possible problems are discussed and solved in once place.

  15. Hello Brian,

    Glad that you liked the post.


    Deep Shah

  16. Hi,
    I have a problem with my android application that it is supossused to connect to a remote interface of a jboss6 aplication server but when i try to do this:

    initCtx = new InitialContext(env);
    x = initCtx.lookup("SessionRemoteAplicationLayer/remote");
    it crachs complitly.. I don't know what to do because I tryed everything that you suggest above and the internet start to work but the problem with my android application don't work.

    Can you please help me? Thanks a lot.

    Sorry about my english, i'm portuguese.

  17. Hi Deep,

    I am facing an issue with the Emulator. I am trying to add a Google Account on the emulator (With Google SDK lvl 8 API) but it keeps giving me 'Could not establish a reliable connection to the server' error.

    I am able to browse from the emulator so there does not seem to be any issue with the network connection.

    I could very easily add a Google account to another emulator on another computer.

    Wondering if you have any clue about what could be going wrong?


  18. Hmm, I have not faced this issue before. But did some googling and found this link

    See if this helps you

  19. Hello Carla Gregório,

    You cannot use InitialContext to lookup a remote service from Android code.

    From Android you can invoke the remote service over HTTP. We mostly return JSON as response from the HTTP Based RESTful service.


    Deep Shah

  20. Hi Friends,

    in my system emulator is opend.while i opened the Xml file(in layout).emulator was skipped.what is the problem ?How can i rectify it?

  21. hello mr.shah

    im using ndk for my application in that it should work as server and client , as a client its working fine but while as server its not working.
    i did permission, dns server as & port forwarding though its not working.


  22. hi friends ,

    i have doubt in android emulator weather emulator can run as server or not in my case its not running as server.can any one suggest it.

  23. you rule.. I've been pulling my hair out trying to figure this out.. finally got a simple http page to download.. damn that was frustrating.. i'm pretty damn proficient in c#, java i understand well enough and can navigate for what i do not. Going nuts, kept thinking, it can't be this damn hard to download a file over the net.. it just can't.. you rule.. and some day when a bag of money falls out of the sky and lands on my head, my will will state you can have 3 hand fulls from it..

  24. Hi Deep,
    Thank you for the great posting.

    My android emulator resolves dns successfully but the browser still saying is not available

    [anna@centos5]./emulator -avd droid -dns-server
    DNS server name '' resolved to

    I do have an internet connection and my browser work fine on centos5.


  25. Looks like my issue is due to the old version of glibc in centos. My centos5 comes with GNU C Library version 2.5. Android emulator needs glibc 2.7. That must be it.


  26. Thanks so much.
    Great job.Hats of to you.

  27. That last solution did it for me. Thank you!

  28. Hello anna,

    Glad that you found a fix. Its worth a blog. May be you should blog about the fix that you found.


    Deep Shah

  29. Hello monkey,

    I totally wish that bag of money falls out of the sky and lands on my head :)


    Deep Shah

  30. Hi: i think i found another issue. The -dns-server gets resolved to port 55, but my company dns servers listen on port 53. Is there a work around to get emulator to use 53 on dns?

  31. Hi,

    I have been trying to access internet through my emulator, every time i open the browser i get the error saying there is no internet connection.
    I tried to follow the steps in your post but there was no options to enter proxy in APN menu.
    Please do suggest the method to overcome this..

  32. I am using windows professional 7. I tried setting DNS server in comment line option
    like this
    -avd Android_2.0 -dns-server
    but getting error DNS server name '' resolved to . How can i fix this.

  33. Thanks alot. I appreciate your blog. It worked for me. Cheers!!

  34. Hello,

    Could you try with the public DNS server


    Deep Shah

  35. hi deep

    I am using ubuntu, i followed your steps, but i could not connect to the net, i am using internet through proxy server.

    Could plz tell me what could be cause?

  36. hi Deep

    i try all that u say but i couldn't success.In my application i try to get information about wifi..Although my browser connect internet my application couldn't see any wireless information..myNetworkInfo.isConnected()return false value

  37. Hello Deep,

    Not able to get my app to connect internet in Android4.0 inspite of adding permission in the manifest file. Tried starting the emulator by specifying the DNS server address but when I run the app I see the below message in my logcat when the line - httpConn.connect(); executes in the code, please note that httpConn is not null.

    LogCat shows Runtime error as - java.lang.RuntimeException: Unable to start activity ComponentInfo{net.learn2develop.HttpDownload/net.learn2develop.HttpDownload.HttpDownload}: java.lang.NullPointerException

    Thanks for your time.

  38. Hello cemile,

    Did add the permissions "ACCESS_WIFI_STATE" and "ACCESS_NETWORK_STATE" to the manifest?


    Deep Shah

  39. Hello Deep,

    Amateur again here. I have tried almost everything. The google on my emulator works but app does not. I tried starting the emulator using google DNS and then installing app, tried my own DNS server IP. I believe my DNS has port 53 while emulator defaults to port 55.My home network does not have a proxy. I tried all after shutting off WINDOWS firewall of my Vista OS on laptop, however no luck. I have wasted 2 days on this issue without getting on the real work :(.

    Any suggestions?

    Thanks for your time.

  40. Hi Deep;

    Yes i added this permissions to manifest.I run my application on mobile it worked properly..I guess emulator couldn't understand if computer connect internet via wireless or ethernet i right?


  41. Hi Deep,
    I am also having the same problem that i am not getting internet on my emulator. I have tried it with the default browser and also with google maps. I am not behind a proxy. I am using a system with fedora 13 OS and am getting internet on my system .I am not running system with admin privilege. I was getting everything perfect and the connectivity suddenly failed one day. I think the issue may be due to DNS as you said.
    How can i fix this issue..Is it through terminal...?


  42. Hey Deep!

    This is really awesome tips!

    I wasted my lot time to start internet in avd manager..But finally I used "emulator.exe -avd AndroidMap -dns-server" command in "Command Prompt" and start the internet and it was done...So great...

    Still, I have one problem, when I run application and start emulator in eclipse, while trying to use internet..I still get the error...

    I tried to solve it out by writing, "-avd Android -dns-server" and "-dns-server" in Eclipses in Window->Preferences->Android->Launch->"Default emulator Option" directory..

    I really have an emergency to solve out this problem. So, if you know where the problem is, then please provide me solution soon....

    Thanks a lot in advance...

  43. This comment has been removed by the author.

  44. Great! Thank you for this very useful information :)

  45. Genius!!! THANKS!!!!

  46. Hi,

    I am developing a SIP protocol based Android application which is having calling features over VOIP.

    I am able to use internet connection when i run that application in emulator but when i run the same application in my samsung galaxy phone then its not able to access internet in it.

    I have already put below line in my application's manifest.xml file

    But still i am facing issue in connecting internet from my phone.
    Note: I am already using SIP based other applications in my same phone, which is able to access internet and functionality also works fine, its just the issue with my developed application.

    Can you please suggest me a way to fix it out?


  47. Dude...You saved lot of my time buddy!!! Thanks a lot!!

  48. Hello Sir,

    I am a newbie in Android development, i am not able to connect to internet after using the below commands, i get the following output

    C:\Program Files\Android\android-sdk\tools>emulator.exe -avd Demodevices -dns-se

    C:\Program Files\Android\android-sdk\tools>DNS server name '' resolved to
    emulator: WARNING: Unable to create sensors port: Unknown error

    i have also included the proxy server and port details of mine as mentioned by you. Kindly help, i am trying to fix this issue for more then a month now.

  49. thanks after a long struggle a find the solution thanks a lot my dear

  50. Hello Deep,
    I am not able hit the internet/intranet through the native apps installed on my android simulator .I have tried all the above options you a provided , still the issue exists. Please note the simulator is installed in VM machine and have all the privileges .please help me in troubleshooting the issue.

    Thanks & Regards

  51. Hey Deep

    You blog is very informative
    However I tried -
    emulator -avd emulatorname -dns-server
    I got the error
    C:\Program Files\Android\android-sdk\tools>DNS server name '' resolved to
    emulator: WARNING: Unable to create sensors port: Unknown error
    I tried also. That didnt work either.gave me a similar error. Im using a script to connect to the internet in internet explorer but no proxy. Could company policies have something to do with this error?

  52. when editing the Androidmanifest, do you use notepad or command prompt?

  53. where can I find the Androidmanifest.xml file? HELP!!

  54. The manifest file (Androidmanifest.xml) is in the root folder of your app-project thus you can find your project files at your android working space directory then you can select the project you want to edit its manifest then good to go, and heey, XML can b edited by using any editor but why suffering find other editors you can still use eclipse to edit any XML file

  55. I just want to know if you are not behind any proxy server, do you still have to provide those username and password, and where do I get them!!

  56. Thanks man. That was very helpful. It did the trick for me. I've been beating my head against the desk all day trying all kinds of scenarios. The whole time all it needed was the dns-server to be set from CLI. - Now, the next thing I need to do is figure out why in the heck the emulator crashes when I attempt to fill in a name field (example... name field for an eMail account, or APN name, or just about any other name field [except for the owner info box, doesn't seem to crash on boxes, just single line fields]).

  57. The trick by me was to use the comand line to execute the emulator, and setting the IP address for the -dns-server x.x.x.x where x is the IP address to my router.
    Thank you very much
    Another question, i am able to access the internet now, but why is the Add account under Accounts & Sync not working?
    Appreciate any help.
    Manny E.

  58. Never faced any such problem before but will keep this in mind if incase in future this type of error arises.

  59. Hi Deep...Thanks for the solution..:) it works perfectly..But everytime i close the emulator and run it again, the apn changes are deleted... and i have to do it again...Its really a headache doing it everytime..Any Solution????
    Thank you,

  60. Hii deep same problem arises with me...I tried with the above command lines but it doesn't work....emulator.exe -avd MapsDevice2.2 -dns-server i used emulator.exe -avd api9 -dns-server
    can u please help me....

    1. I am getting message like this Unknown savevm section type 95

  61. thank you da , emulator.exe -avd And_2.2 -dns-server, works for me

  62. i have tried all the thing you have said ,and my emulator browser work fine but nothing else worked,even map is also does not work plz help ihave already wasted 3 day.

  63. Having a similar problem. Unfortunately the fixes didn't solve it for me.
    Situation: Testing an app for a friend. App needs to connect online to update server. Fails to establish connection.
    Have asked friend if she did the permission-thing. Yup, it is there. Tried the DNS. Same result. Tried setting a proxy. Same result. Tried with and without antivirus enabled.
    Frankly, I'm stumped. The browser on the emulator CAN connect to the net. Just the apps can not.
    Any ideas would be welcome as I have hit a brick wall with this.

  64. Sir please help me out... I am a beginner to android. When i am giving the command emulator.exe -avd<> -dns-server<>.. it says emulator.exe is not recognized as an internal command.. what am i supposed to do...????
    please help me asap...

  65. Good post, thanx loads

  66. Hi!

    I have a problem. Browser not connected to internet.
    No proxy
    -dns-server (I tried also with another)

    not response.

    Antivir offline
    Win7 firewall offline

    Tested with Telkila internet
    I need this for me?
    Deleted internet

    Eclipse reinstall: done
    AVD reinstall: done
    Android SDK reinstall: done

    Browser not connected...why?

    Any idea?


  67. D:\Android\android-sdk\tools>emulator.exe -avd avd2.1 -dns-server

    D:\Android\android-sdk\tools>DNS server name '' resolved to
    Failed to create Context 0x3005
    emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
    what to do i tried everything -dns-server8.8.8.8 and
    what to do
    please reply fast its urgent

  68. You guy save my day.. Thanks from Peru!!

  69. Can't we set Additional Emulator Command line Parameters before Running the Android Application on Emulator. This is available Under Target Tab in Run configuration of the Android Application.

    we can set "-dns-server ,"

  70. thanks a lot man it worked!!
    Thaks ton..

  71. The following worked for me.
    emulator -avd {NameofEmu} -partition-size 500 -no-audio -no-boot-anim -dns-server

  72. Genius!! it worked!! Thanks!

  73. hello i develop android app,in this app i send my data on myhost,
    when i post data using httppost then i got error,

    i try all of this, Internet permission, apn setting dns setting, so on.

    any solution...?

  74. Thanxx worked. :)

    I have done one thing instead of steps mentioned in "Incorrect DNS Used by the Emulator:" topic above.

    I went to eclipse>>Window>>Preference>>Android>>Launch

    within 'Default emulator option' i specified "-dns-server,"

    its seems to be alternative part instead of doing command it??

    but thanxxx other details worked for me..:)

  75. I have been reading this but I still cant get where I'm supposed to change the sever number to please give a step by step explanation


Have some Fun!