3

Is there any way to add Proxy IP and Port in android application so that the internet access will be routed through the Proxy?

From a link i got the information

try { Settings.System.putString(getContentResolver(),
Settings.System.HTTP_PROXY, "127.0.0.1:100");//enable proxy }catch (Exception ex){ }

But by trying this System variable cannot be resolved?

Please help!!

Thanks in advance

2
  • 1
    Can you clarify your question? Do you want to add a proxy for web access via a browser? Why would your app want to change the browser proxy? Commented Jun 8, 2012 at 5:06
  • Hi, my application should also work with proxy server.Android device 2.3.4 directly has no options for setting Proxy server. Commented Jun 8, 2012 at 5:12

1 Answer 1

2
HttpURLConnection con =null;

URL url = new URL("xxxxx");

Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(android.net.Proxy.getDefaultHost(),android.net.Proxy.getDefaultPort()));

con = (HttpURLConnection) url.openConnection(proxy);

Is this okay?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.