Java Code Examples for android.net.Proxy#getDefaultPort()
The following examples show how to use
android.net.Proxy#getDefaultPort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: q.java From letv with Apache License 2.0 | 6 votes |
private static HttpURLConnection a(URL url, String str) throws IOException { String replaceFirst; int i = 80; String defaultHost = Proxy.getDefaultHost(); int defaultPort = Proxy.getDefaultPort(); if (defaultPort == -1) { defaultPort = 80; } String host = url.getHost(); int port = url.getPort(); if (port != -1) { i = port; } if (str.indexOf(new StringBuilder(String.valueOf(host)).append(NetworkUtils.DELIMITER_COLON).append(i).toString()) != -1) { replaceFirst = str.replaceFirst(new StringBuilder(String.valueOf(host)).append(NetworkUtils.DELIMITER_COLON).append(i).toString(), new StringBuilder(String.valueOf(defaultHost)).append(NetworkUtils.DELIMITER_COLON).append(defaultPort).toString()); } else { replaceFirst = str.replaceFirst(host, new StringBuilder(String.valueOf(defaultHost)).append(NetworkUtils.DELIMITER_COLON).append(defaultPort).toString()); } try { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(replaceFirst).openConnection(); httpURLConnection.setRequestProperty("X-Online-Host", new StringBuilder(String.valueOf(host)).append(NetworkUtils.DELIMITER_COLON).append(i).toString()); return httpURLConnection; } catch (MalformedURLException e) { return null; } }
Example 2
Source File: HttpUtils.java From letv with Apache License 2.0 | 6 votes |
private static int a(Context context) { int i = -1; if (VERSION.SDK_INT >= 11) { Object property = System.getProperty("http.proxyPort"); if (TextUtils.isEmpty(property)) { return i; } try { return Integer.parseInt(property); } catch (NumberFormatException e) { return i; } } else if (context == null) { return Proxy.getDefaultPort(); } else { i = Proxy.getPort(context); if (i < 0) { return Proxy.getDefaultPort(); } return i; } }
Example 3
Source File: NetworkUtil.java From Android-Application-ZJB with Apache License 2.0 | 4 votes |
public static String[] getProxyHostAndPort(Context context) { return getNetworkType(context) == NetworkType.WIFI ? new String[]{"", "-1"} : new String[]{Proxy.getDefaultHost(), "" + Proxy.getDefaultPort()}; }