[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
  1. pull database to pc add record (using for example sdk tool sqlite3) and replace existing db
  2. 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>

17 Responses to “[Android] How to set proxy for android browser”

Pages: [2] 1 » Show All

  1. 17
    Manuel Says:

    With the message before I meant that the code works fine and doesn’t produce any errors, but that I’m still unable to use the internet under a proxy.

  2. 16
    Manuel Says:

    Hi, I compiled the code but it doesn’t work in my mobile. I have an HTC Tattoo with Android 1.6

    If anyone wants to try, I uploaded the application .apk, you can download it here: http://www.megaupload.com/?d=NLNYQ4S3 . It’s just Alex’s code with an additional text line saying if the proxy is on or off. It doesn’t work for me, but maybe you can give it a try.

  3. 15
    wifi polimi - Pagina 3 - Forum Android Italiano Says:

    […] Ci sto sbattendo la testa da due giorni e pare che questo sia l’unica via percorribile…ma mi sembra un gran […]

  4. 14
    funktionierendes Proxy APP - Android-Hilfe.de Says:

    […] abnimmt, kenne ich auch nicht. Let’s talk about Google Android: Set proxy for android web browser Android Set up Proxy | Alex Mogurenko`s Blog Evtl. ProxySurf v1.1 Application for Android | Communication ? Sieht aber eher nicht so gut aus. […]

  5. 13
    Murali Says:

    I am also behind a corporate proxy. I should use my username and password.
    How should I specify the user name and password?

  6. 12
    bartoz Says:

    I tried to build the app as you suggest, but if I lanch it I get a force close..
    Could you please revise the code (or even build a usable apk)?
    I’d really appreciate!

  7. 11
    Ali Says:

    I am behind a corporate proxy so not only I need to provide Proxy HOST and PORT but also Username and Password. Any idea how I can do that?

    Thanks

Pages: [2] 1 » Show All

Leave a Reply