How to change the location of the database

Asked

Viewed 210 times

0

I’m creating a database like the SqlOpenHelper and I know that it saves the database in the folder date. I was wondering if there’s a way to move the location of the database to the sdcard for example.

1 answer

1


Just pass the complete path (in class SQLiteOpenHelper) instead of passing only the database name.

abstract class DatabaseManager extends SQLiteOpenHelper {

    private static final String  DATABASE_NAME = "database.db";
    private static final Integer DATABASE_VERSION = 1;

    DatabaseManager(Context context) {
        super(context, Environment.getExternalStorageDirectory()
                + "/Sua-Pasta/" + DATABASE_NAME, null, DATABASE_VERSION);
    }
}
  • This worked ... helped me ... agr am with another doubt ... give me to create a folder in the same address of the folders (layout, menu, drawable) and put my bank there ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.