Appcelerator filesystem and deploying data files at build time - android

I need to install an iOS and Android app built with Appcelerator Alloy which contains a large number of photos (about 200Mb in total). From time to time the user will be able to download new photos from a remote server, but only at the rate of about 10Mb each time.
I have built the app and it works fine using the Resources directory, but I now realise this can only be read (not deleted or updated) by the app on devices. I am not clear about where in the project filesystem I should put the photo files so that they will be in the ApplicationDataDirectory when the app is installed. Do I need to somehow move/copy all the data from the resources directory into the ApplicationDataDirectory at build time? Seems a bit long-winded....
Sorry a bit of a long question, but can't find an answer anywhere!
Any help or advice much appreciated.

In my case I'm using applicationDataDirectory.
I've a lot of pictures, at the download time, in order to the device don't run out of memory, after downloading the image file, wait one second and goes to the next one, every time that I download those images, I'm deleting the old ones.
Delete old ones and its folder, create a new folder:
var path = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'products');
if(path.exists()) path.deleteDirectory(true);
path.createDirectory();
After downloading the image:
Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'products'),'image.png').write(this.responseData);

Related

Is there a way to set a cache limit for my Android app?

I want to set a cache limit for my android app. My app is creating PNG files periodically and saving them to a folder on the phone it's installed on. I want it so if the folder hits this limit (10MB) it will automatically start deleting the files starting with the oldest ones deleting only a certain amount at a time (9MB). I also want this process to run in the background of the phone.
How do I do this? Screenshots would be most helpful. Thank you.
I'm using Android Studio 2.2.2. My app needs to work for Android 4.4.
There is no per-application limit for the cache directory.
Look here : Limit size of cache directory

How to handle 150 Mb of raw videos and music files in Android

I've been developing this content-based app for Android which includes over 120 MB of video .mp4-files saved on the raw folder and in addition it includes over 20 MB of sound files also saved in the raw folder.
The problem is I cannot install the app on my Android phone due to limited internal memory to handle all those files. Also, I read somewhere that the app size limit on the Android market is 50MB so I won't be able to even upload the damn thing.
I've saved the videos on the raw folder as I was able to play them fine (using VideoView).
My question is how do i cope with such size, do I have to go through making the user download the content after installing the app or is there any other way of dealing with such sizes (~140 MB).
You cannot distribute an APK through the market that is more than 50MB. Its not a good idea to take up 120MB of the internal storage for a single app as many phones don't have a lot of internal storage space.
You should consider stripping out all of the large files, hosting them on a server and then having the application download the files on the first launch. I would also recommend you save the files to the SD card so you don't use up too much of the precious internal storage.
Edit: I will admit that any time an app tries to download a lot of data on the initial launch I get really frustrated. Make sure you do it in a way that doesn't require the activity to be open the entire time the file is downloading. Do the downloading through a service so the user can at least use their phone while your app is downloading the media files.
Well, if you're sure you need all this content inside your application, the only solution I see is to download the content from a server when the application is opened for the first time. But as a user I think I won't be very happy to have a 150 Mb application on my phone. Do you really need all this data?

80Mb mp3 files+40 MB images,what is the best place?assets or Raw?eclipse takes time to Build?(android 3.0)

I have approximately 80MB+ mp3 files,40MB images in my project.when I try to put 3MB of each these files eclipse takes a lot time to build.is it possible to put all these files in Raw or assets folder?what is the solution to make eclipse build fast.
I think for best practice is to make the user download these files after he installes your app since Android market limits your app size to 50MB.
You can use
AsynTask to download the data asynchronously
I have this same issue, and came to the same conclusion as khr2003. I just want to add that the real limit for Android Market is more like 30MB since an app larger than that is impossible to download to most phones -- you will get out of storage errors.

Android: Download media or store in app?

I'm currently working on an app which downloads a zip file and extracts a bunch of tiny mp3 files into external storage. The zip file is about 2.5 meg.
I'm wondering if it would be a better idea to include the zip file in app resources, and then copy and extract it to the file system. This would prevent the headaches involved in something like a lost connection during the zip file download. I noticed some missing mp3s, and when I checked the zip file, the last 20 or so weren't it it. So, it looks like the system can successfully (an unfortunately) extract from an incomplete zip file.
The downside including the zip file in app resources is obviously that it increases the size of the app by 2.5 meg. I've specified "prefer external storage" in the manifest. This isn't supported before release 2.2, i.e. level 8, so I'm already excluding those phones, which probably is 20 or 30 percent of the total android phones. But I'm not entirely sure if that guarantees the app will be installed on the SD card.
It could be worth including the zip file in the app just to avoid the potential hassles in handling the download of the zip file; but if the size of the app makes it unappealing, then that's kind of a drawback - especially if the "prefer external" doesn't work on some devices.
Which is the better option? Ideas are welcome.
One of the highest selling Android Games, Gun Bros, does what you are thinking about: small app, that downloads the content on demand. This allows them to also serve ads while the content is downloading. In addition, by downloading the content you can make use of compression over the network thus reducing the total amount of data a user will actually have to use to get the whole application. I think in the end it is a personal preference, but I would lean towards downloading over the network.
Given the fact that there are some apps/games out in Android market which are in the 40+ MB range a 2 MB additional download doesn't seem that much to me. Anyway your users have to download it one way or another. Either in the apk or as a separate zip file.
Now Android market allows you to post updates to your application so your users can get new content through there.
Regarding prefer external storage, it is just that - a preference. If external storage is not available or a user is installing it on a 2.1 phone, then it will install the application to internal storage, as long as your applications minimum SDK level is 7 or lower.
But there are other applications I can think off that download content from sites, things like scripting for android (SL4A). If you want to update your game content that way, I would recommend creating a mechanism whereby your application can first discover the size of the download, then do the download. And once the download completes, verify the size against the size it should be. If the two don't match, then run the download again or something like that.
I'd recommend just including it in the apk file. Many apps on the market are like 5-10 MB, and games can be even bigger (I've seen games range anywhere from 1 MB to 40 MB), so adding 2,5 MB to your app shouldn't really be a problem, even if they don't support installing to sd-cards.
My phone for example have 2.1 and therefor can't install to the sd-card and I've so far never run out of space even after installing a bunch of 2-5 MB apps.
And no "prefer external storage" does not guarantee that it's installed on the sd-card, if the user doesn't have an sd-card for example, or if they choose themselves to move it to the internal storage.
Point is, adding 2,5 MB to your apk isn't anything anyone will really notice or care about, and you shouldn't need to either.

Android App size problem

I have 11 videos to include in my App. Each of them is around 9MB. Besides those, I have to a few sound files and image files in the app. Therefore the app size is going 100+MB. Is there any way to accommodate all the files so that app size does not become an issue for me?
Download the files after starting the app for the first time.
Puh..that's quite large. In such a situation I'd
Let the user download your app not containing any videos/audio files that cause the large size
At first run guide the user through a wizard where you download the additionally needed files to the SD card.
Still, downloading nearly 100MB won't be ideal, but better than directly download all of it at the first install. (IMHO)
The most common sollution i've seen is downloading them during the first run of the programme. Just check if everything is available, and if it isn't, download the needed files.
pros:
This way you can also add video's on the fly.
APK size stays small so initial download is quick
Cons:
after downloading the app you can't directly use it: content must be downloaded first
I would suggest you to put them in the assets folder, so they will not be compressed.
This way you'll have problems testing your project with eclipse, so try building it with command line, and then install on device with adb
In my scenario, I had 300+ videos, totalling upto 400+ MB of the size.
I checked with few of them and deployed the app the way i just told.
may not be the best way around, but may work.
You can upload into youtube or make your own simple video streaming server

Categories

Resources