Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the android database storage path?

Tags:

android

How do I change the android database storage path? The default path for database storage is / data / data / databases,I want to save it to sdcard, how to do?

like image 983
fonter Avatar asked Oct 12 '10 01:10

fonter


1 Answers

This is and old question, but answering may help others.

The easiest way to do this (only for debuggin environments) is to modify the constructor of the class:

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    MySQLiteOpenHelper(Context context) {
        super(context, "/mnt/sdcard/database_name.db", null, 0);
    }
}

Remember to change for production environments with these lines:

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    MySQLiteOpenHelper(Context context) {
        super(context, "database_name.db", null, 0);
    }
}
like image 103
RandomUser Avatar answered Sep 28 '22 14:09

RandomUser