使用程序中的 Galaxy HTTP 代理设置
如何以编程方式读取 WiFi 代理设置?
GalaxyS 和 GalaxyTab 有自己的 HTTP 代理设置,专门用于操作系统级别的 WiFi 连接。 (菜单 -> 设置 -> 无线和网络 -> Wi-Fi 设置 -> 菜单键,然后是高级)这是一个非常好的功能,否则您将无法使用 WiFi 的代理服务器。 (请参阅问题 http://code.google.com/p/android /issues/detail?id=1273)
现在我的应用程序使用普通 HttpClient 的 http 连接。我想从操作系统读取代理设置并放入连接中,但我不知道如何读取它。
使用 getprop 命令,我可以读取 APN 的代理设置,但不能读取 WiFi 的代理设置。 APN 代理设置使用密钥“net.gprs.http-proxy”存储。
adb -d shell
$ getprop net.gprs.http-proxy
getprop net.gprs.http-proxy
http://proxy.example.com:8888/
$
WiFi屏幕的高级设置在com.android.settings.wifi.AdvancedSettings中实现,当然,首选项存储在/data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml中。我只是无法从我的应用程序中读取该文件,对吗?
我想我会陷入困境,除非三星提供特殊的 API 来访问该设置,但我找不到此类信息。顺便说一句,包括我在内的许多应用程序在全局 HTTP 代理设置方面都会有很大的优势,所以我希望有一种方法......
How can I read WiFi-Proxy setting programmatically?
GalaxyS and GalaxyTab have their own HTTP-Proxy setting specially for WiFi connection in OS level. (Menu -> Settings -> Wireless and network -> Wi-Fi setting -> Menu Key and then Advanced) It's very nice feature for otherwise you cannot use proxy servers from WiFi. (See the issue http://code.google.com/p/android/issues/detail?id=1273)
Now my application use http connection with usual HttpClient. I want to read the proxy setting from OS and put into the connection but I don't know how to read it.
With getprop command I can read proxy setting for APN, but not for WiFi. APN proxy setting is stored with key "net.gprs.http-proxy".
adb -d shell
$ getprop net.gprs.http-proxy
getprop net.gprs.http-proxy
http://proxy.example.com:8888/
$
The Advanced Setting for WiFi screen is implemented in com.android.settings.wifi.AdvancedSettings and, naturally, the preference is stored in /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml. I just cannot read the file from my application, right?
I guess I'm stuck unless Samsung provides special API to access the setting but I couldn't find such information. BTW, many applications including mine will have great advantages with global HTTP proxy setting so I hope there is a way...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
未来版本的 Android 将不会使用 net.gprs.http-proxy。他们将改为使用 java VM 属性 http.proxyHost、http.proxyPort 和 http.nonProxyHosts(也设置了 https)。大多数 http 堆栈已经符合此标准,因此您不需要作为应用程序开发人员进行额外的工作。
代理设置将从 APN 数据库中读取(与以前一样),但也会从每个 wifi-AP 数据库中读取,因此 wifi 和移动数据都会受益。
这在 HC 及其他地区都已实施。如果你想检查你的代理设置,你可以使用 System.getProperty("http.proxyHost") java 调用。
Future versions of android won't use net.gprs.http-proxy. They will instead use the java VM properties http.proxyHost, http.proxyPort and http.nonProxyHosts (https also set). Most http stacks are already compliant with this standard so you don't need to do extra work as an app developer.
The proxy settings will be read from the APN db (as it used to be) but will also be read from a per-wifi-AP db, so both wifi and mobile data will benefit.
This is in place in HC and beyond. If you want to check your proxy settings you can just use the System.getProperty("http.proxyHost") java call.