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
In Object Explorer, right-click on your server and click Properties. In the left panel on that Properties page, click the Database settings tab. In Database default locations, view the current default locations for new data files and new log files.
To change a default location, enter a new default pathname in the Data or Log field, or click the browse button to find and select a pathname.
When you save the location, it's saved as DefaultData and DefaultLog under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer The Work around to resolve this issue is to restart the SQL server or SQL services 1.
Right-click the new DefaultHomeFolder key, select New > String Value, and name it Location. Double-click the new Location string value and change its value to the path of the desired Home folder. Is This Content Helpful?
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
UPDATE
If you target Android 10 or higher, set the value of requestLegacyExternalStorage to true in your app's manifest file:
<manifest ... >
<!-- This attribute is "false" by default on apps targeting
Android 10 or higher. -->
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With