Android's proxy confusing documentation resources

北慕城南 提交于 2019-12-18 13:25:45

问题


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?


回答1:


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.




回答2:


I don't know if it's the "right" way to access the proxy settings but it's the right and only way you should access the system "secure settings".

Maybe this is also interesting, looks like it makes things easier, especially if there are Wifi proxys (does Android support something like this?). At least it looks like great abstraction for the various android versions.



来源:https://stackoverflow.com/questions/9332522/androids-proxy-confusing-documentation-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!