本文整理汇总了Java中android.net.Proxy类的典型用法代码示例。如果您正苦于以下问题:Java Proxy类的具体用法?Java Proxy怎么用?Java Proxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Proxy类属于android.net包,在下文中一共展示了Proxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkIsProxyNet
import android.net.Proxy; //导入依赖的package包/类
public static boolean checkIsProxyNet(Context context) {
boolean isAboveICS;
String proxyAddress;
((WifiManager) context.getSystemService("wifi")).getConnectionInfo();
if (VERSION.SDK_INT >= 14) {
isAboveICS = true;
} else {
isAboveICS = false;
}
if (isAboveICS) {
proxyAddress = System.getProperty("http.proxyHost");
} else {
proxyAddress = Proxy.getHost(context);
}
if (TextUtils.isEmpty(proxyAddress)) {
return false;
}
return true;
}
示例2: a
import android.net.Proxy; //导入依赖的package包/类
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;
}
}
示例3: 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;
}
}
示例4: b
import android.net.Proxy; //导入依赖的package包/类
private static String b(Context context)
{
if (android.os.Build.VERSION.SDK_INT < 11)
{
if (context != null)
{
String s = Proxy.getHost(context);
if (TextUtils.isEmpty(s))
{
s = Proxy.getDefaultHost();
}
return s;
} else
{
return Proxy.getDefaultHost();
}
} else
{
return System.getProperty("http.proxyHost");
}
}
示例5: 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;
}
示例6: registerReceiver
import android.net.Proxy; //导入依赖的package包/类
private void registerReceiver() {
if (mProxyReceiver != null) {
return;
}
IntentFilter filter = new IntentFilter();
filter.addAction(Proxy.PROXY_CHANGE_ACTION);
mProxyReceiver = new ProxyReceiver();
mContext.getApplicationContext().registerReceiver(mProxyReceiver, filter);
}
示例7: detectProxy
import android.net.Proxy; //导入依赖的package包/类
private String detectProxy() {
String proxyUrl = null;
if (!TextUtils.isEmpty(Proxy.getDefaultHost())) {
proxyUrl = String.format(FORMAT_PROXY_URL, new Object[]{Proxy.getDefaultHost(), Integer.valueOf(Proxy.getDefaultPort())});
}
LogTool.i(TAG, "detectProxy. detected the proxy url(%s)", proxyUrl);
return TextUtils.isEmpty(proxyUrl) ? "" : URLEncoder.encode(proxyUrl);
}
示例8: b
import android.net.Proxy; //导入依赖的package包/类
private static String b(Context context) {
if (VERSION.SDK_INT >= 11) {
return System.getProperty("http.proxyHost");
}
if (context == null) {
return Proxy.getDefaultHost();
}
String host = Proxy.getHost(context);
if (TextUtils.isEmpty(host)) {
return Proxy.getDefaultHost();
}
return host;
}
示例9: v
import android.net.Proxy; //导入依赖的package包/类
public static HttpHost v(Context context) {
if (context == null) {
return null;
}
try {
if (context.getPackageManager().checkPermission("android.permission" +
".ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
return null;
}
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return null;
}
if (activeNetworkInfo.getTypeName() != null && activeNetworkInfo.getTypeName()
.equalsIgnoreCase("WIFI")) {
return null;
}
String extraInfo = activeNetworkInfo.getExtraInfo();
if (extraInfo == null) {
return null;
}
if (extraInfo.equals("cmwap") || extraInfo.equals("3gwap") || extraInfo.equals
("uniwap")) {
return new HttpHost(Network.CMWAP_GATEWAY, 80);
}
if (extraInfo.equals("ctwap")) {
return new HttpHost("10.0.0.200", 80);
}
String defaultHost = Proxy.getDefaultHost();
if (defaultHost != null && defaultHost.trim().length() > 0) {
return new HttpHost(defaultHost, Proxy.getDefaultPort());
}
return null;
} catch (Throwable th) {
cT.b(th);
}
}
示例10: c
import android.net.Proxy; //导入依赖的package包/类
private HttpHost c() {
String g;
if (VERSION.SDK_INT >= 11) {
g = g();
if (g != null && !g.contains("wap")) {
return null;
}
URL b = b();
if (b == null) {
return null;
}
b.a.equalsIgnoreCase(b.getProtocol());
Object property = System.getProperty("https.proxyHost");
String property2 = System.getProperty("https.proxyPort");
if (TextUtils.isEmpty(property)) {
return null;
}
return new HttpHost(property, Integer.parseInt(property2));
}
NetworkInfo f = f();
if (f == null || !f.isAvailable() || f.getType() != 0) {
return null;
}
g = Proxy.getDefaultHost();
int defaultPort = Proxy.getDefaultPort();
if (g != null) {
return new HttpHost(g, defaultPort);
}
return null;
}
示例11: d
import android.net.Proxy; //导入依赖的package包/类
private HttpHost d() {
NetworkInfo f = f();
if (f == null || !f.isAvailable() || f.getType() != 0) {
return null;
}
String defaultHost = Proxy.getDefaultHost();
int defaultPort = Proxy.getDefaultPort();
if (defaultHost != null) {
return new HttpHost(defaultHost, defaultPort);
}
return null;
}
示例12: setLollipopWebViewProxy
import android.net.Proxy; //导入依赖的package包/类
/**
* Set Proxy for Android 5.0 and above.
*/
@SuppressWarnings("all")
private static boolean setLollipopWebViewProxy(Context appContext, String host, int port) {
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port + "");
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port + "");
try {
Class applictionCls = Class.forName("android.app.Application");
Field loadedApkField = applictionCls.getDeclaredField("mLoadedApk");
loadedApkField.setAccessible(true);
Object loadedApk = loadedApkField.get(appContext);
Class loadedApkCls = Class.forName("android.app.LoadedApk");
Field receiversField = loadedApkCls.getDeclaredField("mReceivers");
receiversField.setAccessible(true);
ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
for (Object receiverMap : receivers.values()) {
for (Object rec : ((ArrayMap) receiverMap).keySet()) {
Class clazz = rec.getClass();
if (clazz.getName().contains("ProxyChangeListener")) {
Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
/***** In Lollipop, ProxyProperties went public as ProxyInfo *****/
final String CLASS_NAME = "android.net.ProxyInfo";
Class cls = Class.forName(CLASS_NAME);
/***** ProxyInfo lacks constructors, use the static buildDirectProxy method instead *****/
Method buildDirectProxyMethod = cls.getMethod("buildDirectProxy", String.class, Integer.TYPE);
Object proxyInfo = buildDirectProxyMethod.invoke(cls, host, port);
intent.putExtra("proxy", (Parcelable) proxyInfo);
onReceiveMethod.invoke(rec, appContext, intent);
}
}
}
} catch (Exception e) {
Log.e(LOG_TAG, "Setting proxy with >= 5.0 API failed with", e);
return false;
}
Log.d(LOG_TAG, "Setting proxy with >= 5.0 API successful!");
return true;
}
示例13: setUseProxy
import android.net.Proxy; //导入依赖的package包/类
public static void setUseProxy (boolean useProxy) {
HttpParams params = getHttpClient().getParams();
if (useProxy) {
try {
params.setParameter(ConnRouteParams.DEFAULT_PROXY, new HttpHost(Proxy.getDefaultHost(), Proxy.getDefaultPort()));
} catch (Exception e) {
e.printStackTrace();
}
} else {
params.removeParameter(ConnRouteParams.DEFAULT_PROXY);
}
}
示例14: onReceive
import android.net.Proxy; //导入依赖的package包/类
@Override
public void onReceive(Context context, final Intent intent) {
if (intent.getAction().equals(Proxy.PROXY_CHANGE_ACTION)) {
runOnThread(new Runnable() {
@Override
public void run() {
proxySettingsChanged(ProxyReceiver.this, extractNewProxy(intent));
}
});
}
}
示例15: registerReceiver
import android.net.Proxy; //导入依赖的package包/类
private void registerReceiver() {
if (mProxyReceiver != null) {
return;
}
IntentFilter filter = new IntentFilter();
filter.addAction(Proxy.PROXY_CHANGE_ACTION);
mProxyReceiver = new ProxyReceiver();
ContextUtils.getApplicationContext().registerReceiver(mProxyReceiver, filter);
}