Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Proxy p = ProxyUtils.getProxy("http://www.google.com", "8080");
- Log.i("Proxy", "" + p.address().toString());
- ProxyConfiguration pc = ProxySettings.getProxySdk12(getActivity(), NetworkUtils.getWifiConfiguration(getActivity()));
- pc.writeConfigurationToDevice();
- // class ProxyUtils
- /**
- *
- * @author Sajmon
- *
- */
- public class ProxyUtils {
- public static String getHostFromURL(String url) {
- try {
- InetAddress address = InetAddress.getByName(new URL(url).getHost());
- return address.getHostAddress();
- }
- catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public static Proxy getProxy(String url, String port) {
- int proxyPort = Integer.parseInt(port);
- Proxy p = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(getHostFromURL(url), proxyPort));
- return p;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment