2015-09-14 85 views
1

我有一個應用程序與數據/數據/ com.endel.psicotest /數據庫/ psico.dbAndroid。要連接到數據庫secundary其他路徑

一個本地sqllite數據庫工作,但我試圖連接到secundary和舊的db在/data/data/com.example.psicotestv1/databases/

但是當我試過SQLiteDatabase db = getReadableDatabase();在我DataBaseHelper_OLD 返回我的第一個數據庫 :(

public DBMain_OLD(Context contexto) { 
    super(contexto, DB_NAME, null, DB_VERSION); 

    //Calculamos la ruta de la base de datos 
    File file = new File(contexto.getDatabasePath(DB_NAME).getPath()); 
    DB_PATH_OLD = "data/data/com.example.psicotest3/databases/"; 
    this.context = contexto; 
} 

我secundary構造與DB_PATH_OLD

DataBaseHelper_OLD myDbHelper_OLD = new DataBaseHelper_OLD(contexto); 
    Item item_OLD = myDbHelper_OLD.GetItemId(idPregunta); 

我拿到第一個數據庫:(

回答

0

的價值。如果你想分享一個數據庫在2個應用程序之間,你將需要實現一個ContentProvider。你不能共享一個簡單的數據庫,因爲一個應用程序通常不能訪問其他應用程序的文件夾(我通常說因爲具有root ac可以)。這就是爲什麼當你撥打SQLiteDatabase db = getReadableDatabase();時,你只能從你的應用獲取數據庫。

Content Provider Guide