List of usage examples for android.net Proxy getHost
@Deprecated public static final String getHost(Context ctx)
From source file:android.core.ProxyTest.java
@Override protected void setUp() throws Exception { super.setUp(); mContext = getContext();/*from w ww .j ava 2s. c o m*/ mHttpHost = null; String proxyHost = Proxy.getHost(mContext); int proxyPort = Proxy.getPort(mContext); if (proxyHost != null) { mHttpHost = new HttpHost(proxyHost, proxyPort, "http"); } }
From source file:net.primeranks.fs_viewer.fs_replay.ConnectionChangedBroadcastReceiver.java
public void onReceive(Context context, Intent intent) { String info = intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO); NetworkInfo nwInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); Log.d(Config.LOG_AS, info + ": " + nwInfo.getReason()); HttpParams httpParams = EntryPointActivity.getHttpClient().getParams(); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(context); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); }// w ww . j av a2 s . c om int proxyPort = Proxy.getPort(context); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:com.android.internal.location.GpsXtraDownloader.java
byte[] downloadXtraData() { String proxyHost = Proxy.getHost(mContext); int proxyPort = Proxy.getPort(mContext); boolean useProxy = (proxyHost != null && proxyPort != -1); byte[] result = null; int startIndex = mNextServerIndex; if (mXtraServers == null) { return null; }//from w ww . j a va 2 s . c om // load balance our requests among the available servers while (result == null) { result = doDownload(mXtraServers[mNextServerIndex], useProxy, proxyHost, proxyPort); // increment mNextServerIndex and wrap around if necessary mNextServerIndex++; if (mNextServerIndex == mXtraServers.length) { mNextServerIndex = 0; } // break if we have tried all the servers if (mNextServerIndex == startIndex) break; } return result; }
From source file:com.github.diogochbittencourt.googleplaydownloader.downloader.impl.DownloadThread.java
/** * Returns the preferred proxy to be used by clients. This is a wrapper around {@link Proxy#getHost()}. Currently no * proxy will be returned for localhost or if the active network is Wi-Fi. * * @param context the context which will be passed to {@link Proxy#getHost()} * @param url the target URL for the request * @return The preferred proxy to be used by clients, or null if there is no proxy. * @note Calling this method requires permission android.permission.ACCESS_NETWORK_STATE *///from w w w. j a v a 2s. c o m public HttpHost getPreferredHttpHost(Context context, String url) { if (!isLocalHost(url) && !mService.isWiFi()) { final String proxyHost = Proxy.getHost(context); if (proxyHost != null) { return new HttpHost(proxyHost, Proxy.getPort(context), "http"); } } return null; }
From source file:com.github.ignition.support.http.IgnitedHttpClient.java
public void updateProxySettings() { if (appContext == null) { return;/*from w w w.j a v a 2s. c om*/ } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(appContext); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:com.DGSD.DGUtils.Http.BetterHttp.java
public static void updateProxySettings() { if (appContext == null) { return;//w ww . j a va 2 s .c om } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(appContext); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:cn.edu.szjm.support.http.IgnitedHttp.java
/** * Updates the underlying HTTP client's proxy settings with what the user has entered in the APN * settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)} * has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE} * permission</b>./* w w w. j av a 2s . co m*/ * * @param context * the current context */ public void updateProxySettings(Context context) { if (context == null) { return; } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(context); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(context); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:com.mobeelizer.mobile.android.MobeelizerRealConnectionManager.java
private void setProxyIfNecessary(final HttpRequestBase request) { String proxyHost = Proxy.getHost(application.getContext()); if (proxyHost == null) { return;/* www . jav a2 s .c o m*/ } int proxyPort = Proxy.getPort(application.getContext()); if (proxyPort < 0) { return; } HttpHost proxy = new HttpHost(proxyHost, proxyPort); ConnRouteParams.setDefaultProxy(request.getParams(), proxy); }