Search code examples
androidsqliteassets

Open SQLite Database directly from assets folder


A related Question is asked here. The tutorials show how to copy the database, but I want to open it directly, So I started with this code but it seems that there is an error that I wasn't able to know

SQLiteDatabase db = SQLiteDatabase.openDatabase("file:///android_asset/quiz.sqlite", null, SQLiteDatabase.OPEN_READWRITE);

I can create a database and work on it and I can copy an existing database an work on it, But how to open it directly from the assets folder?


Solution

  • but I want to open it directly

    That is not possible, sorry. An asset is not a file. It is an entry in the ZIP archive that makes up an APK. SQLite has no means of working with an asset. file:///android_asset/ is a hack for use with WebView; it does not work for arbitrary other pieces of code.