I enabled proxy settings in 2.2 and 2.3 version of android in emulator and the internet started working but I have an application installed (which works only with proxy) is still not working. When I did the same for 4.0 version emulator, it was working there. Can anyone tell, why is it not working on 2.2 and 2.3 version though the internet is working.
No, they do not apply globally and without root there is no way to force a proxy to be used by all applications. The reason the message you found is worded that way is that it is up to the app creator to respect the proxy settings and use them or do the wrong thing and ignore them.
I also set up a proxy for the emulator in the Eclipse environment. It properly added the proxy address to the emulator startup command.
Yet I still struggled with it working only in some apps (like the browser) and not in others (like Maps) until I went into the WiFi settings in the emulator and entered the proxy address.
Note you can't use http://
before the DNS name in this setting as you can in the emulator startup line. (That took an hour to figure out.)
You should try this (for Android 2.3):
1. > adb shell
2. # sqlite3 /data/data/com.android.providers.settings/databases/settings.db
3. sqlite> INSERT INTO system VALUES(99,’http_proxy', 'proxy:port');
4. sqlite>.exit
Also, you could try to define proxy explicitly when launching emulator via argument http-proxy
emulator -avd yourAVD -http-proxy http://yourproxy:port
Configuring your proxy in the emulator allows the Browser application to use it, but any other applications need to be HTTP Proxy capable to access the internet.
Assuming you use the DefaultHttpClient class to connect to the internet, you'll have to add the following code to your android application before making the connection:
DefaultHttpClient client = new DefaultHttpClient();
HttpHost proxy = new HttpHost("yourproxy.domain.com", 3128);
// Enter your proxy domain and port
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
If you are using an authenticated proxy, you'll need to also have these lines:
client.getCredentialsProvider().setCredentials(
new AuthScope("yourproxy.domain.com", 3128),
new UsernamePasswordCredentials("proxyusername", "password"));
Since you want the same code to work on both the emulator as well as a real phone, you should add a setting to the app which allows the user to turn on or off use of the proxy, and enter the proxy server/port/credentials instead of hard-coding them in the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With