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();
}
}
Aucun commentaire:
Enregistrer un commentaire