问题
I want to change the location of the Android Room Database. I know that the database is inside of the files system, and I need to get root permissions, but I do not want to root my phone.
The idea is change the database location to SD card, and can access it without root my phone
回答1:
Just put the location path in the name of the database.
I.e.:
AppDatabase db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "database-name").build();
Put the router in database name.
I.e.:
AppDatabase db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "/storage/emulated/0/folder/database-name").build();
and do not forget to give the write permissions to the application
thx @vitidev
来源:https://stackoverflow.com/questions/48645801/how-can-i-change-the-default-location-of-a-room-database