[Android] How to set proxy for android browser
There are many reasons to make browser serf pages through proxy server:
- someone wanna catch http requests/responses
- someone wanna hide his IP
- so on
What to do if you want set proxy for android browser? there some ways:
- add record to database: /data/data/com.android.providers.settings/databases/settings.db
- pull database to pc add record (using for example sdk tool sqlite3) and replace existing db
- make changes in database directly on device
but as for me there exist simplier way, do it by your Java application using Settings provider:
Settings.System.putString(getContentResolver(), Settings.System.HTTP_PROXY, "proxy_ip:proxy_port");
where proxy_ip/proxy_port = IP/port of proxy that you going to use.
there left one problem, it will not work if we will not add one string to manifest file, here it is:
<uses-permission android:name=”android.permission.WRITE_SETTINGS” />
Thats all, now it works, here is code:
package com.BrowserSettings;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.provider.Settings;
public class BrowserSettingsUI extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try
{
Settings.System.putString(getContentResolver(), Settings.System.HTTP_PROXY, "127.0.0.1:100");//enable proxy
}catch (Exception ex){
}
}
});
final Button button2 = (Button) findViewById(R.id.Button02);
button2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try
{
Settings.System.putString(getContentResolver(), Settings.System.HTTP_PROXY, "");//disable proxy
}catch (Exception ex){
}
}
});
}
}
manifest file:
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.BrowserSettings”
android:versionCode=”1″
android:versionName=”1.0.0″>
<application android:icon=”@drawable/icon” android:label=”@string/app_name”>
<activity android:name=”.BrowserSettingsUI”
android:label=”@string/app_name”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
<uses-permission android:name=”android.permission.WRITE_SETTINGS” />
</manifest>
Filed under: Programming
June 23rd, 2011 at 7:32 am
[…] ?????????([Android] How to set proxy for android browser),???????????????。???????,????,?????。 […]
October 19th, 2010 at 6:59 pm
An easer way: http://androidero.blogspot.com/2010/10/acessando-wifi-via-proxy.html
September 21st, 2010 at 10:55 am
just install with a easy way…(note you need root access for that)
http://forum.xda-developers.com/showthread.php?t=766569
August 31st, 2010 at 12:04 pm
[…] Android Set up Proxy | Alex Mogurenko`s Blog (tags: android) […]
August 10th, 2010 at 8:21 pm
According to API document, the Settings.System.HTTP_PROXY setting is deprecated:
http://developer.android.com/reference/android/provider/Settings.System.html#HTTP_PROXY
and the new one is under Settings.Secure:
http://developer.android.com/reference/android/provider/Settings.Secure.html
However, it wrote:
“Secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications. ”
It it seems to be impossible to change like this now?
Or like Joe at #9 saying, need some permission?
July 14th, 2010 at 11:25 am
Yes, it works at my Hero
July 8th, 2010 at 7:30 am
Using ECLIPSE I modified a “helloworld”-kind application, added the permission in the androidmanifest.xml () and included the Setting suggested after a text message. No compiler errors, transferred on device (HTC desire), but no results… still I cannot browse internet.
Probably the “set” command is not really working, or it is inhibited by permission problem…?
Greg Ruo
PS: Below is the code I used
================================
package com.BrowserSettings;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.provider.Settings;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText(”! Should Set proxy OK !!”);
setContentView(tv);
Settings.System.putString(getContentResolver(), Settings.System.HTTP_PROXY, “xxx.xxx.xxx.xxx:8080″);
}
}
=========================================-