我尝试访问另一个应用程序的数据库,我想从我的应用程序中插入该数据库的数据。我在我的手机上测试它(root)但我得到错误。谁能帮我?
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)
以下是文件, 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();
}
}
答案 0 :(得分:1)
我找到了解决方案:
我对该应用程序的'databases'文件夹和该数据库文件执行了chmod 777。现在我可以从我的应用程序中插入数据。