本文整理汇总了Java中android.net.Proxy.getPort方法的典型用法代码示例。如果您正苦于以下问题:Java Proxy.getPort方法的具体用法?Java Proxy.getPort怎么用?Java Proxy.getPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.Proxy
的用法示例。
在下文中一共展示了Proxy.getPort方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: a
import android.net.Proxy; //导入方法依赖的package包/类
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;
}
}
示例2: getProxy
import android.net.Proxy; //导入方法依赖的package包/类
/**
* @param context context
* @param info current network info
* @return the proxy to be used for the given network, or null
*/
public static String getProxy(Context context, NetworkInfo info) {
final String proxy;
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
// adjust mobile proxy settings
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) {
proxy = new HttpHost(proxyHost, proxyPort).toURI();
} else {
proxy = null;
}
} else {
proxy = null;
}
return proxy;
}
示例3: getPreferredHttpHost
import android.net.Proxy; //导入方法依赖的package包/类
/**
* Returns the preferred proxy to be used by clients. This is a wrapper
* around {@link android.net.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 android.net.Proxy#getHost()}
* @param url the target URL for the request
* @note Calling this method requires permission
* android.permission.ACCESS_NETWORK_STATE
* @return The preferred proxy to be used by clients, or null if there is no
* proxy.
*/
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;
}
示例4: getPreferredHttpHost
import android.net.Proxy; //导入方法依赖的package包/类
/**
* Returns the preferred proxy to be used by clients. This is a wrapper
* around {@link android.net.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 android.net.Proxy#getHost()}
* @param url the target URL for the request
* @note Calling this method requires permission
* android.permission.ACCESS_NETWORK_STATE
* @return The preferred proxy to be used by clients, or null if there is no
* proxy.
*/
@SuppressWarnings("deprecation")
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;
}
示例5: getPreferredHttpHost
import android.net.Proxy; //导入方法依赖的package包/类
/**
* 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
*/
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;
}