1

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...

4

1 回答 1

1

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.

于 2011-07-08T17:45:42.117 回答