Android 的代理令人困惑的文档资源 [英] Android's proxy confusing documentation resources

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

问题描述

在我看来,关于 Android 上的代理主题有很多令人困惑的资源.

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:

"使用标准的 java vm 代理值来查找主机、端口和排除清单.此调用会忽略排除列表."

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

官方java vm 代理值可以通过以下方式访问:

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")

ProxySelector 类的文档似乎证实了这一点.

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

但是在真实设备或模拟器上尝试时,这些值在我看来总是空的.查看隐藏的ProxySelector activity,貌似代理是通过以下方式保存到系统的安全设置中的:

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);

有人可以澄清这是否是对如何将代理设置访问到 Android 的正确解读?(至少它似乎有效).如果这是正确的解释,为什么文档中充满了错误?

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?

推荐答案

对于获取代理值,像您所做的那样访问系统属性应该可以工作;应该没有必要访问安全设置.如果您无法使用系统属性来读取通过正常设备 UI 进行的代理设置,则说明存在问题.代理是针对每个网络类型的,因此 APN 和 WiFi 将具有单独的代理设置.

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天全站免登陆