简体   繁体   English

Android系统。 在其他路径下连接到二级数据库

[英]Android. To connect to secundary database in other path

I have an app working with a single local sqllite database in data/data/com.endel.psicotest/databases/psico.db 我有一个使用data / data / com.endel.psicotest / databases / psico.db中的单个本地sqllite数据库的应用程序

but I'm trying to connect to a secundary and old db in /data/data/com.example.psicotestv1/databases/ 但是我正在尝试连接到/data/data/com.example.psicotestv1/databases/中的二级旧数据库

but when I had tried SQLiteDatabase db = getReadableDatabase(); 但是当我尝试SQLiteDatabase时db = getReadableDatabase(); in my DataBaseHelper_OLD return me the first database :( 在我的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;
}

my secundary constructor with the DB_PATH_OLD 我的DB_PATH_OLD次构造器

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

I got the value of first database :( 我得到了第一个数据库的价值:(

If you want to share a DB between 2 apps, you will need to implement a ContentProvider . 如果要在2个应用程序之间共享数据库,则需要实现ContentProvider You can't share a simple database because an application normally can't access other applications' folders. 您无法共享简单的数据库,因为一个应用程序通常无法访问其他应用程序的文件夹。 (I said normally because apps with roots access can). (我之所以这么说,是因为具有root用户访问权限的应用程序可以)。 And this is why when you call SQLiteDatabase db = getReadableDatabase(); 这就是为什么当您调用SQLiteDatabase db = getReadableDatabase(); you only get the DB from your app. 您只能从应用程序中获取数据库。

Content Provider Guide 内容提供商指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM