How to modify the Sqlite Path

1

I can not change the path of SQLITE .

I set up a database in android studio and the class that extends from SQLiteOpenHelper

I have:

public Constructor (Context ctx){
        super(ctx, NombreBase, null, 1)
}

public void onCreate(SQLiteDatabase db){
        db.execSQL("create table miTabla (ID integer ,Nombre text)");
}

What happens is that you save the database in:

data/data/miproyecto/NombreBase.db  

And I want for example to keep it in:

data/data/otronombre/NombreBase.db

So the question is how do I modify the location so that it changes the path ?

Thank you.

    
asked by YANINA 19.12.2017 в 04:06
source

1 answer

3

In the constructor you must pass the path where you want to save the database, for example:

public class MyDataBase extends SQLiteOpenHelper {
 MyDataBase(Context context) {
    super(context, "/mnt/sdcard/NombreBase.db", null, 1);
 }
}

You must make sure that your application has the necessary permissions to be able to save files in the external storage.

For security it is not recommended to save the database in a path external to that of your app.

Please comment if it has served you!

    
answered by 19.12.2017 / 04:21
source