Android SDK: Data exceeds UNCOMPRESS_DATA_MAX

I’m finishing up my first app (attaBase) and testing it on the minimum API I set: 8. That’s Android 2.2. My app grabs a 4MB CSV file and imports all the DoD locations (Military bases, etc). The problem is, the old APIs (up to 2.3.3 I think) have a limit of 1MB of uncompressed data in the assets folder. So, I had to work around this limitation.  

I found a tip on Stack Overflow to zip the file yourself and use a ZipInputStream to unzip it on the fly. Since I’m only ever accessing this large file once in the lifetime of my app, that’s fine. I ended up editing the Stack Overflow answers I link to above to provide examples, but here is my code that accepts a zipped file and unzips it on the fly:

AssetManager am = getAssets();
InputStream is;
ZipInputStream zip;
InputStreamReader isr;
try {
    is = am.open(AttaBaseContract.IMPORT_SOURCE_ZIP);
    zip = new ZipInputStream(is);
    isr = new InputStreamReader(zip);
    zip.getNextEntry();
} catch (IOException e) {
    e.printStackTrace();
    return -1;
}

int skipline = 1;
CSVReader reader = new CSVReader(isr, CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER, skipline);

This is assuming there is only one file in the zip file, because it will only feed the first file to the CSVReader (in this case). This is a nice workaround if you’re trying to make your app compatible to an old API.

Leave a comment

Your email address will not be published. Required fields are marked *

Loading...