Search code examples
androiddatabasesqliteopenhelper

How to read data from database in assets without copying


In database file (in assets) I need read some date without copying this databse on device. I didnt find answer in google for correct work.

Is it possible?


Solution

  • No, you can not do that because all the assets are compiled in a binary form and android preserve the names of all the asset's file from which it can access the file at runtime...! Project Resources, Please see the main/assets on the link

    Android SQLiteDatabaseHelper needs some kind of InputStream...!

    Alternatives:

    • You can copy the database from your assets directory to the android app directory. For refference see this link...!

    • You can copy the database from assets to sdcard and then access it....! Please see this link..!

    • You can use a JSON, XML or GSON format intead of SQLITE (not recommended)