I want to configure proxy using code.

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

I want to configure proxy using code.

Postby amitnargund » Mon Dec 29, 2008 12:29 pm

I know the command to configure the proxy settings:
adb shell sqlite3 /data/data/com.google.android.providers.settings/databases/settings.db "\"INSERT INTO system VALUES(99,'http_proxy','[HOST]:[PORT]');\""

But I want to configure this through the code.

Here is what I am doing

SQLiteDatabase db=SQLiteDatabase.openDatabase("/data/data/com.google.android.providers.settings/databases/settings.db", null, SQLiteDatabase.OPEN_READWRITE);
db.execSQL("INSERT INTO system VALUES(99,’http_proxy', 'host:port)");

But I am constantly getting the Exception cannot open the database.

Can anybody tell me where I am doing wrong.

Also I read somewhere that Android does not allow you to access settings.db outside the data/data/com.google.providers.settings package. Is that true??
amitnargund
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 25, 2008 7:34 am

Top

Postby MrSnowflake » Mon Dec 29, 2008 1:51 pm

You shouldn't and can't do this using the database. Remember ContentProviders? This is where you use them.

This should help you:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Cursor Settings =getContentResolver().query(System.CONTENT_URI, new String[]{System.NAME, System.VALUE}, System.NAME+"=?", new String[]{System.HTTP_PROXY}, null);
  3.  
  4. if (Settings != null) {
  5.  
  6.         if (Settings.moveToFirst()) {
  7.  
  8.                 String proxyAddress = Settings.getString(Settings.getColumnIndex(System.VALUE));
  9.  
  10.         }
  11.  
  12. Settings.close();
  13.  
  14.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

Now you only should use the update function of the ContentProvider instead of the query command, but it works similarily.

You should also have the read write permission for system settings.

[edit]Fixed.
Last edited by MrSnowflake on Tue Dec 30, 2008 12:14 pm, edited 1 time in total.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby amitnargund » Tue Dec 30, 2008 6:42 am

Thanks for the reply!

I would like to know what mSetting? It is object of which class?
amitnargund
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 25, 2008 7:34 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests