Android的代理混乱的文档资源 [英] Android's proxy confusing documentation resources

查看:240
本文介绍了Android的代理混乱的文档资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,有很多关于Android上的代理话题混乱的资源。

首先,似乎 Proxy类的所有方法都宣告德precated,它的建议:

  

使用标准的Java虚拟机的代理值来查找主机,端口和   排除列表。此调用忽略排除列表中。

可以在访问官方 Java虚拟机的代理值下列方式:

  System.getProperty(http.proxyHost)
System.getProperty(把http.proxyPort)
System.getProperty(http.nonProxyHosts)
 

这似乎可以通过的ProxySelector类的文件证实。

但是,试图真实的设备或仿真器上,这些价值观对我来说总是空的。细算的隐藏ProxySelector活动的,似乎该代理被保存到系统以下列方式中的安全设置:

  Settings.Secure.putString(RES,Settings.Secure.HTTP_PROXY,主机名);
 

和仅由操作系统提供商签署的应用程序可以写入的安全设置。开发者可以通过以下方式访问仅在读模式下这些设置:

<$p$p><$c$c>Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.HTTP_PROXY);

有人可以澄清,如果这是一个如何可以访问的代理服务器设置成Android的正确的阅读? (至少它似乎工作)。如果这是正确的INTE pretation,为什么文档如此错误百出?

解决方案

有关获取代理值,访问为你做了应该工作的系统性能;它不应该是必要的访问安全设置。如果您无法使用系统属性读通过正常的设备的用户界面所做的代理设置,那么有一个问题。代理是针对每个网络类型,所以APN和WiFi都会有不同的代理服务器设置。

It seems to me that there is a lot of confusing resources regarding the proxy topic on Android.

First of all, it seems that all the methods of the Proxy class are declared deprecated and it's suggested to:

"Use standard java vm proxy values to find the host, port and exclusion list. This call ignores the exclusion list."

The official java vm proxy values can be accessed in the following way:

System.getProperty("http.proxyHost")
System.getProperty("http.proxyPort")
System.getProperty("http.nonProxyHosts")

This could seem confirmed by the documentation of the ProxySelector class.

But trying on a real device or an emulator, these values seems to me always empty. After looking to the Android source code of the hidden ProxySelector activity, it seems that the proxy is saved into the secure settings of the system in the following way:

Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, hostname);

And only an application signed by the OS provider can write to the secure settings. Developers can access these settings only in read mode in the following way:

Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.HTTP_PROXY);

Someone can clarify if this is the correct reading of how can be access the proxy settings into Android? (At least it seems to work). If this is the correct intepretation, why the documentation is so full of errors?

解决方案

For getting proxy values, accessing the System properties as you have done should work; it should not be necessary to access secure settings. If you cannot use the System properties to read proxy settings that were made through the normal device UI, then there is a problem. Proxies are per network type, so the APN and WiFi will have separate proxy settings.

这篇关于Android的代理混乱的文档资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆