Android Emulator and Proxy

by Nirmal Patel » Fri, 18 Mar 2011 14:47:35 GMT


Sponsored Links
 I am confused with how the Proxy settings work in the Android emulator.

I am able to access internet in the browser by configuring my Proxy settings 
on the APN (TelKila)
However, my App is not able to access internet. (uses-permission mentioned 
in AndroidManifest.xml)

I am using HttpClient in my app to make a web service call which fails with 
a UnknownHostException.
To access internet through HttpClient; I have to add proxy settings to 
HttpClient explicitly in my code.


Shouldn't HttpClient pick up the proxy settings configured on the APN?? 


-- 



Re: Android Emulator and Proxy

by Ramsay Domloge » Fri, 18 Mar 2011 19:12:26 GMT


 When you say 'HttpClient', I assume you mean Apache HTTPClient?

If so, this is a toolkit for accessing HTTP content from a Java context, 
whether Java is running in Android, in a Java applet running in Firefox on 
Windows or running in a backend Unix Application server. HttpClient is not 
specific to Android and therefore doesn't intrinsicly know how to 'talk' to 
Android to discover how Android is configured with a Proxy. You will need to 
bridge this gap.






-- 


Sponsored Links


Re: Android Emulator and Proxy

by Finch » Fri, 18 Mar 2011 21:41:58 GMT


 Try starting the emulator with "emulator .... -http-proxy 
http://proxyserver:port"

This will make the emulator use the specified proxy "globally" and
will work fine for development and testing.
I'm not sure what happens if one of your users needs to use a proxy
later on. I'd guess there's a way to retrieve the proxy settings?

I do know that a proxy can be specicified in HttpClient. Wait, let me
google that for you:
HttpClient client = new HttpClient();
client.getHostConfiguration().setProxy(proxyHost, port);

I cannot tell you how to retrieve the connection's proxy settings in
Android, but luckily, that was not your question :-)





-- 



Re: Android Emulator and Proxy

by Nirmal Patel » Fri, 18 Mar 2011 22:52:00 GMT


 Yes, I am using Apache HttpClient. 

I do not understand what you mean when you say "bridge this gap"??

Do you mean:

I need to provide the proxy settings to HttpClient explicitly?? I am doing 
the same right now by 
      HttpHost httpproxy = new HttpHost("10.0.2.2", 5865); // a proxy 
running on my machine
     
 httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,httpproxy);
However, this proxy is only applicable for our dev environment. Whereas 
actual users when running the app on their mobiles will be having direct 
access to internet. I am not sure how do I strip these proxy code from my 
builds??


Or do you mean

there is a way to query Android to find the proxy settings configured on the 
APN and pass them to HttpClient? Personally, I haven't come across those 
yet.


-- 



Re: Android Emulator and Proxy

by Nirmal Patel » Fri, 18 Mar 2011 23:00:59 GMT


 I did try to start the emulator by specifying the command line option but 
neither of the following works for me...

-http-proxy 127.0.0.1:5865
-http-proxy 10.0.2.2:5865


With either above... I am unable to access internet in emulator browser...  


--