Monday, August 26, 2013

[android-developers] Manual Proxy Configuration not working on Android 2.3

I am using a Samsung Galaxy S Plus Phone running on Android 2.3.4

I manually set the proxy server and the port in the phone, in Settings-> Wireless & Network-> Wi-Fi Settings-> MENU Button-> Advanced panel.

My phone is still not able to communicate using the proxy. I tried the browser, and that is not able make use of the proxy settings.

public static InputStream inputStreamForUrl(URL url) throws IOException {            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); // doesn't work on android 2.3.4          urlConnection.setRequestMethod("GET");          urlConnection.setDoInput(true);          urlConnection.setConnectTimeout(30000);          urlConnection.setReadTimeout(30000);          System.out.println(urlConnection.usingProxy());          urlConnection.connect();          return urlConnection.getInputStream();  }

However, If I manually hardcode the proxy in the code, it works

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.server.url", 8080));// this needs to be hard coded to make it work in 2.3  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(proxy);// this needs to be hard coded to make it work in 2.3

I tried to dynamically find out the system proxy and then use it in code,

private static void getProxySettings()      {          final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= 14;            String proxyAddress = "";          int proxyPort = 0;            if( IS_ICS_OR_LATER )          {              proxyAddress = System.getProperty( "http.proxyHost" );                String portStr = System.getProperty( "http.proxyPort" );              proxyPort = Integer.parseInt( ( portStr != null ? portStr : "-1" ) );          }          else          {              proxyAddress = android.net.Proxy.getHost( ctx );              proxyPort = android.net.Proxy.getPort( ctx );          }                System.out.println(proxyAddress);          System.out.println(proxyPort);      }

but the proxy address and port is null always.

Can someone help please

PS. I absolutely no problem on Android 4.1/4.2/4.3 devices

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment