androidsqliteandroid-sqliteandroid-databaseandroid-rom

Deploy Android Application with Initial SQLite database


I need to use a Database in Android and I have read that a good way at the moment is using Room Library. But my case is a little different I don't want the database to write information on runtime I want to deploy the application with an SQLite dabase already created and with data inside.

What is the folder to put the DB file in Android Studio project? How to access this from app using Room?

Thanks


Solution

  • use this library implementation'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'

    and paste the database in your asset folder and in your sql helper call put the database name

     private class SqL extends SQLiteAssetHelper{
    
        public SqL(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    }
    

    where DATABASE_NAME is your databse name and DATABASE_VERSION is your database version