1

i try to access a database of another application, i want to insert data on that database from my application. I test it on my phone (rooted) but i get errors. Can anyone help me?

12-30 00:01:27.315: E/SQLiteLog(10477): (14) os_unix.c:30241: (13) open(/data/data/com.otherapplication/databases/records.db) - 12-30 00:01:27.376: E/SQLiteDatabase(10477): Failed to open database '/data/data/com.otherapplication/databases/records.db'. 12-30 00:01:27.376: E/SQLiteDatabase(10477): at com.test.MySQLiteOpenHelper.insertData(MySQLiteOpenHelper.java:28) 12-30 00:01:27.376: E/SQLiteDatabase(10477): at com.test.MainActivity.test(MainActivity.java:45) 12-30 00:01:27.446: E/AndroidRuntime(10477): at com.test.MySQLiteOpenHelper.insertData(MySQLiteOpenHelper.java:28) 12-30 00:01:27.446: E/AndroidRuntime(10477): at com.test.MainActivity.test(MainActivity.java:45) 

Here are the files, MySQLiteOpenHelper.java :

package com.test; import java.util.HashMap; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class MySQLiteOpenHelper extends SQLiteOpenHelper { MySQLiteOpenHelper(Context context) { super(context, "/data/data/com.otherapplication/databases/records.db", null, 1); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } public void insertData() { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("id", "testvalue"); database.insert("table", null, values); database.close(); } } 

MainActivity.java

public class MainActivity extends Activity { MySQLiteOpenHelper controller = new MySQLiteOpenHelper(this); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void test(View v) { controller.insertData(); } } 
6
  • Only the application itself can access its local data. If you want to connect 2 apps together, you need to use exported DataProviders. Commented Dec 29, 2014 at 22:18
  • i want to access the database of other application which i didn't created it, it isn't possible? Commented Dec 29, 2014 at 22:19
  • No. Unless that application saves it's database in the memory card. Which is highly unlikely. Commented Dec 29, 2014 at 22:20
  • so is there any way to do this thing which i want? ex. copy the database to somewhere then insert the data after replace it with the other? Commented Dec 29, 2014 at 22:21
  • No sane application would allow that. Think of all the data you could steal... Commented Dec 29, 2014 at 22:22

1 Answer 1

1

I have found the solution:

I did chmod 777 to that application's 'databases' folder and that database file. And now i can insert data from my application.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.