1

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 copying it to database/ folder but since the file is >1Mb this gives me an IOException. Then I tried to access it from raw folder but its still giving me IOException. So, what is the correct way to access such a file. Also, in future the app might need to download such files from server, so in that case where should I store such database files?

Thanks!!

techno
  • 773
  • 2
  • 8
  • 16

3 Answers3

2

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.

nicholas.hauschild
  • 42,483
  • 9
  • 127
  • 120
  • Added some solutions to my answer. – nicholas.hauschild May 15 '11 at 05:13
  • Thanks for the link. The changing of extension of the file in assets folder from .sqlite to ".jpg" worked!! I know this is not the best solution but it works!! – techno May 15 '11 at 05:27
  • Hi, is the 1MB limitation still there for new Android OS now? I can't find any documentation that talk about this. Do you have any idea where can I find it? – – Sam YC Nov 22 '12 at 03:39
0

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.

Amit Chintawar
  • 20,450
  • 1
  • 17
  • 17
  • That's not really true. The limitation is for all compressed files. Some file extensions are by default not compressed since it is not useful -- .mp3 is one of them. – hackbod May 15 '11 at 07:18
  • Hi, is the 1MB limitation still there for new Android OS now? I can't find any documentation that talk about this. Do you have any idea where can I find it? – – Sam YC Nov 22 '12 at 03:39
0

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.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117