Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apps under proxy not working in emulator though internet is working

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.

like image 310
Rookie Avatar asked Jul 05 '12 08:07

Rookie


People also ask

Do android proxy settings apply to all apps on the device?

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.


3 Answers

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.)

like image 118
Gene Avatar answered Sep 22 '22 20:09

Gene


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
like image 20
Arseniy Avatar answered Sep 19 '22 20:09

Arseniy


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.

like image 31
Rajesh J Advani Avatar answered Sep 23 '22 20:09

Rajesh J Advani