Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Proxy IP and Port in android code?

Tags:

android

proxy

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

like image 491
info Avatar asked Feb 11 '26 00:02

info


1 Answers

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?

like image 79
hungr Avatar answered Feb 12 '26 16:02

hungr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!