Way around 1mb file size restriction? - android

My app needs to save files that will range from about 2-20mb. When I tried to do this I was getting an OutOfMemoryException. I did some reading and it's looking like Android has a file size limit of 1mb. Is this correct? If so, is there a way around this limitation, other than splitting up every file into 1mb chunks?

The main application need to be small, like < 1 MB but you can save as many files as you want and as large as you want as long as you save them on the memory card. The available space that can be used for applications (and other secure data) is limited, usually under 128 MB. So basically you need to keep your application small and put the large part as an add-on or extra files that can be put on the memory card. If you application will use 20MB from the available space it will drastically reduce the number of people that will use it.

OutOfMemoryError means you exceeded the VM's RAM budget, which is 16MB or 24MB depending on what device you're on. It has nothing to do with file sizes.
The 1MB limit you're probably referring to is the maximum size of a compressed asset in an APK file.
Files in your app-private data area or on external storage can be as large as the filesystem will allow them to be. (I've heard the FAT32 implementation Android uses for SD cards has a 2GB limit for individual files, but don't remember the resolution of that thread.) Available disk space will likely be a larger concern.
Going back to your original problem, check the logcat output (via adb logcat or DDMS) to see if there are any messages from the garbage collector right before the OOM fired.

Related

Is Android sdcard minimum file size always 4kb?

I am using a DiskLruCache to store around 70k files. These files are really small, half of them are not even 13 bytes each. However each file size is at least 4kb in disk because I assume that's the minimum block size. Therefore when I set a maxSize for the cache of 256MB the cache actually grows above the 450MB in disk.
I modified the code in DiskLruCache so it takes in consideration that files are stored in 4kb blocks.. however, my question is, can I rely that every Android device will always divide its sdcard in 4kb blocks? Could it be that another device has a bigger or smaller block size?
I used StatFs(directory.getAbsolutePath()).getBlockSize()

Max File Size & Quantity for Android and iOS

I'm developing an app that will download large files (mostly videos). What I need to know is this:
Is there a max singe file size imposed by either Android or iOS? All I've seen is the 4GB limit of a FAT filesystem. The max video size should come no where near that, but we want to be 100% sure that there isn't a lower limit
Is there a max amount of space allocated to a single app on either system? Google turned up nothing on this question, so I am going to assume there isn't a limit beyond available file space (which seems logical, but also far to free for an Apple-built system)
Is there a max number of individual files or directories for either system? Again, Google turned up nothing. I don't see why there would be here, but I want to cover all the bases here.
Thanks!
All answers here are for Android:
Is there a max singe file size imposed by either Android or iOS? All I've seen is the 4GB limit of a FAT filesystem.
I would not exceed 4GB.
Is there a max amount of space allocated to a single app on either system?
No, there is no per-app quota system at this time. That being said, try not to make users regret using your app. :-)
Is there a max number of individual files or directories for either system?
Yes, but since the counts should be in the millions, your app will grind to a halt long before you hit those limits.
Can't answer for iOS, but for Android, your APK can't exceed 50MB (if it does, you can include expansion files for your additional data).
Here is the link to the docs explaining all the details:
http://developer.android.com/guide/google/play/expansion-files.html

Max app space (storage)

I've looked around and have noticed that the max size for an apk is 50MB, but I am curious as to how much application space an app can download. Can one app take up all of the application storage or does it need to download additional content into the internal storage and/or sd card?
Thanks
The APK limit has been increased from 50MB to 4GB (see http://androidcommunity.com/android-market-upgrading-app-size-limit-to-4gb-20110511/ ), so one would presume that an app could store up to 4GB.
That said, you should be storing any large files on SD card (or similar) instead of taking up the app space (some phones this is shared space, such as the Galaxy Nexus.) Doing it that way won't have any limits except the space available on the SD card from my understanding.

Android VM heap strategies for big images

I am manipulating relative large images, about 5MP and sometimes even more. I need two copies of the images in memory for manipulation.
Now, the loaded images consume a lot of memory, more than available by the default Android heap which is 16MB respectively 24MB which results in the following error:
11-20 18:02:28.984: E/AndroidRuntime(7334):
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
I need full resolution, thus downscaling while loading the images does not help.
What's the best solution to get over this problem? Are there built-in methods to dynamically load only chunks of bitmaps from storage? And can someone give me some hints how I can overcome the memory problem, e.g. by using specific caching strategies?
Regards,
You can allocate more memory in the ndk. You'd have to write native code to manipulate the images, or you'd have to figure out a way to allocate the image memory in native, then pass it back to Java.
Bitmap/Canvas use and the NDK
Another option might be to load a single image into memory, and break it up into chunks for processing. Save those chunks out to the file system. So, say you 2 large images. You load the first image, break it into 4 parts, save them, load the second, break it into 4 parts, save those, then load part #1 for each image, and do your thing. That implies you know that neither individual image is larger than the heap max, and that what you need to do is (basically) pixel level and doesn't need access to surrounding pixel data (you'll run into trouble at the edges if you need neighbor pixel info).
Without downsampling, splitting, or ndk, I don't know how you'd get more image data into memory. Perhaps lowering the color info. We do this in a product. Represent each pixel as 16 bits rather than 24 or 32. Our product is functional rather than "pretty", so the loss of color info wasn't a big deal.
You should watch this video on memory management: http://www.youtube.com/watch?v=_CruQY55HOk
At about 6 mins into it he covers the LargeHeap manifest option added to HoneyComb.

Android: Out of memory error when loading text files. How to get available memory before loading files

I want to load a text file in a wordprocessing apps. But I get out of memory error when files are of too big. I finalized that I can load upto 1 MB files. But sometimes I get out of memory even for 1MB files. But I have to say before loading whether I can load files or not.
I tried for solution of finding maximum possible available memory, apart from freeMemory(),
that is freememory + (maxmemory - totalmemory) which will give the total possible available memory for the application. (Say it will be around 18MB to 20 MB). But I get outofMemory error after completely utilizing the heap. say for example(24 MB).
My question is really that (18MB to 20 mb) of "maximum possible available memory" is utilized for allocation when loading 1MB file.
How much of memory should be available to load 1MB file.
How can I roughly compute it.
Is there any way out of PSS, Privatedirty. I couldn't understand much about PSS. But I couldn't get much info regarding of summing up in article "How to discover memory usage of my application in Android"
Thanks
Remember, the way you store the files in variables matters quite a lot. Using char array manually is one of the most memory-efficient ways, but you still need to account for every character taking 16 bits, or 2 bytes. So, if you have text file using some 8-bit encoding and you load it into char array, it takes twice as much space.

Categories

Resources