How does android access a sqlite database included in the assets folder

后端 未结 5 1234
借酒劲吻你
借酒劲吻你 2020-12-18 07:31

I already have a SQLite database. I put it in the assets folder of my project. I read the Android documentation. It said that for all the databases in Android,

5条回答
  •  温柔的废话
    2020-12-18 07:45

    When you create a database by utilizing the SQLiteDatabase or SQLiteOpenHelper classes, it creates the database in your data/data/package_name/database.

    You can access that resource by using

    InputStream myInput = myContext.getAssets().open(your_database_here);
    

    Any other information, look at Using your own SQLite database in Android Applications

    The package_name portion of the path, would be the name of your package. You can find the name of the package at the first line in your .java files.

    As an example, my class starts with this at the top

    package com.forloney.tracker;
    

    So my database is in data/data/com.forloney.tracker/database folder.

    Hope this makes sense.

提交回复
热议问题