I'm no expert, but it looks like you might be having trouble with the
proxy rather than trouble setting a proxy from Android.

Can you use the proxy elsewhere, e.g. from a web browser?

You say that setting the proxy worked until Android 1.6 -- can you use
the proxy if you use an early SDK version?

Here are some ways to use the emulator behind a proxy -- not sure
which of these you've tried.

1. Set the default proxy from Windows > Preferences > Android >
Launch.

2. Add '-http-proxy http://www.example.com:80' to Debug Configurations
> Target (pane) > Additional Emulator Command Line
Options (you need to resize the dialog to see this).

3. Set the proxy on the emulator from Settings > Wireless controls >
Mobile Networks > Access Point Names > T-Mobile US > ...

For me, none of these works on its own -- though a colleague tells me
that 2. works on his Mac.

What works best for me in most contexts is to set the proxy on the
emulator (as per 3.) and then use the following in my code:

final String proxyHost = android.net.Proxy.getDefaultHost();
final int proxyPort = android.net.Proxy.getDefaultPort(); // returns
-1 if not set
if (proxyPort != -1)
{
        System.setProperty("http.proxyHost", proxyHost);
        System.setProperty("http.proxyPort",
Integer.toString(proxyPort));
}

With DefaultHttpClient, I do this:

client = new DefaultHttpClient();

String proxyHost = android.net.Proxy.getDefaultHost();
int proxyPort = 0;
proxyPort = android.net.Proxy.getDefaultPort();
if (proxyPort > 0) // !!!hack: this means that a proxy has been set
{
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);

} else {
        Log.d("Proxy could not be set for port: ",
Integer.toString(proxyPort));
}


Sam Dutton



On Feb 19, 12:37 pm, Vibhor Mahajan <mahajan.vib...@gmail.com> wrote:
> Hello,
>
> I am trying to configure http_proxy settings for Internet access from
> Android emulator (behind a proxy). I tried following options:
>
> 1. -http-proxy option using emulator command.
> 2. setting http_proxy environment and then launching the emulator.
> 3. Settings proxy using APN settings (Telkilla) (this worked till
> Android 1.6 version)
> 4. adding an entry in settings.db <adb shell  sqlite3 /data/data/
> com.android.providers.settings/databases/settings.db "INSERT INTO
> system VALUES(101,'http_proxy','10.0.0.27:80');">
> adb shell  sqlite3 /data/data/com.android.providers.settings/databases/
> settings.db "SELECT * FROM system"
>
> I also checked -debug-proxy log messages and it showed below messages
> emulator.exe -avd avd_21 -debug-proxy -http-proxy
> http://vibhor.mahajan:xyz~1...@10.0.0.27:80
> proxy_http_setup: creating http proxy service connecting to:
> 10.0.0.27:80
> server name '10.0.0.27' resolved to 10.0.0.27:80
> proxy_http_setup: creating HTTP Proxy Service Footer is (len=63):
> 'Proxy-authorization: Basic dmliaG9yLm1haGFqYW46eHl6fjEyMzQ=
>
> '
> http_service_connect: trying to connect to 209.85.231.104:80
> http_service_connect: using HTTP rewriter
> tcp:209.85.231.104:80(1496): cannot connect to proxy: <unknown error>
> http_service_connect: trying to connect to 209.85.231.104:80
> http_service_connect: using HTTP rewriter
> tcp:209.85.231.104:80(1496): cannot connect to proxy: <unknown error>
> http_service_connect: trying to connect to 209.85.231.104:80
> http_service_connect: using HTTP rewriter
> tcp:209.85.231.104:80(1456): cannot connect to proxy: <unknown error>
> http_service_connect: trying to connect to 209.85.231.104:80
> http_service_connect: using HTTP rewriter
> tcp:209.85.231.104:80(1440): cannot connect to proxy: <unknown error>
> http_service_connect: trying to connect to 10.0.0.22:80
> http_service_connect: using HTTP rewriter
> tcp:10.0.0.22:80(1440): cannot connect to proxy: <unknown error>
> http_service_connect: trying to connect to 10.0.0.22:80
> http_service_connect: using HTTP rewriter
> tcp:10.0.0.22:80(1440): cannot connect to proxy: <unknown error>
>
> Kindly suggest how can we access Internet from emulator (behind a
> proxy).
>
> Thanks,
> Vibhor

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to