accessing .sqlite database (>1Mb size) in android

后端 未结 3 1922
陌清茗
陌清茗 2021-01-23 20:23

I am working on a library app and have books stored as .sqlite files. Each book\'s sqlite database file is about 10MB in size. I first tried to put it in assets folder and then

相关标签:
3条回答
  • 2021-01-23 20:34

    Have the app download the database from a web server to the sdcard - this saves the waste of storing both a compressed version in the .apk and an uncompressed version outside. And it's not really any more insecure as an .apk is just a zip file anyone who really wants to can read.

    0 讨论(0)
  • 2021-01-23 20:46

    There is a workaround to this issue. The limitation of 1MB is only for SQLite files and not for other file types. Rename your SQLite file as something like "db.mp3" and then when your app starts, you can copy this file to your SD Card and use it as a normal SQLite file from SD card. I have implemented this solution and it works perfectly fine on all Android versions.

    0 讨论(0)
  • 2021-01-23 20:55

    Before Android 3.0 you are not allowed to open files larger than 1mb.

    From the link: [P]rior to Android 2.3, any compressed asset file with an uncompressed size of over 1 MB cannot be read from the APK.

    Here are some solutions:

    1. Perhaps you want to look into shrinking the size of the databases, and that might be by making your own, or by removing some of the entries that you do not need/want.

    2. Another solution would be to offload the databases to a server that you have access to and require the application to access the web to get the data that is necessary from this server. I can imagine a nice RESTful API to do this.

    0 讨论(0)
提交回复
热议问题