Connecting to internet from an Android emulator through a proxy server

Usually I use linux with squid as a proxy server on the same PC and the Android emulator does not connect to internet returning the error “Web page not available” as in Figure 1.

Figure 1

To set up squid as a proxy for the emulator you can not use 127.0.0.1 as the IP address because for the emulator it is the address of the mobile device and not the localhost.
On the site Android Developers I found the following page Using the Android Emulator where you read:

Also note that the address 127.0.0.1 on your development machine corresponds to the emulator’s own loopback interface. If you want to access services running on your development machine’s loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.

Then to configure the Android emulator to use the squid proxy server on the localhost go to:
Menu -> Settings -> Wireless & networks -> Mobile networks -> Access Point Names -> TelKila
where you set Proxy to 10.0.2.2 and Port to 3128 as in Figure 2.

Figure 2

Alternatively you can enter in the menu of Eclipse, Run Configurations, as Additional Emulator Command Line Options, -http-proxy http://10.0.2.2:3128 as in Figure 3.

Figure 3

With this second method I get an error starting the emulator in the Eclipse console:

emulator: Could not connect to proxy at 10.0.2.2:3128: Connection timed out !
emulator: Proxy will be ignored !

but everything seems to work properly.


Comments

One response to “Connecting to internet from an Android emulator through a proxy server”

  1. kindly let me know the solution of above mentioned scenario

    I connected a emulator through a command sucessfully
    emulator -avd myavd -no-audio -http-proxy 127.0.0.1:18800

    But an update of avd i getting the an error for same above command

    emulator: Could not connect to proxy at 127.0.0.1:3128: Connection timed out !
    emulator: Proxy will be ignored !

    I downgrade my avd but still facing the same issue

    I am facing same issue while using the command -http-proxy 127.0.0.1:18080

Leave a Reply to Umair Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.