Opening a read-only database directly in the resource folder

I found a lot of questions on this site about how to open a database file located in the resource folder. Always the main point of the correct answer is the same: the databases located in the assets cannot be opened, since such a folder (like all APK content) is read-only. Therefore, the database file must be copied somewhere else before using it ( send the application with the database ).

However, what if the database file does not actually need to be modified ?. In this case, the restriction on access to the resource folder does not matter.

Then my questions are:

Is there a way to open a read-only database in a resource folder without copying it to another location

+5
source share
2 answers

Use the OPEN_READONLY flag, for example.

SQLiteDatabase.openDatabase(myPath,null,OPEN_READONLY);

You can find more flags here.

And I think you need to copy the database to another location in order to open it first.

0
source

You need to copy it to the data folder, then read from there.

0
source

All Articles