我想为我的 Android 应用程序提供嵌入式数据库。在网上搜索时,我发现人们将其发送到应用程序的 Assets 中,然后在安装时/首次运行时将其复制到其他目录。
就我而言,我需要一个只读数据库,所以我不想制作它的多个副本。是否可以直接从 Assets 中使用它?有没有办法节省空间?
最佳答案
In my case I need a Read-Only DB so I don't want to make multiple copies of it. Is it possible to use it directly from assets? Is there a way to save that space?
没有。 Assets 不是设备中的常规文件,sqlite 库无法直接读取它们。
要么只使用例如复制文件sqlite-asset-helper或者不使用 sqlite 数据库,而使用可以与 AssetManager
提供的 InputStream
配合使用的数据库。
关于Android嵌入式数据库只读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33342888/