Saturday, 15 March 2014

Bundling files with Android app and allowing for additional downloads later -


I have an app that comes with a bunch of small images (about 200 images) (~ 10 MB total Size) in different cases on screen when the user presses a button, one of these images is displayed (any of them can be). More images may be added at any time in the future, so the app checks for an XML document on the server (this check is done in the cret of the main activity; if this check was already done, at least 24 hour). The XML document lists all the images, so it's easy to check whether the document was changed and new images were added. If more images have been added, then the app will download these images from the server and store them with images already present on the device.

My first thought was to bundle 10 MB images with the app, they are put in the Asset folder and the app will start for the first time, images will move from the asset folder to the internal storage. Then if any other images will be added in the future, they will be downloaded and saved in internal storage, so all the images are getting well together, although after using some experiment I found that it takes a lot of equipment For the time (test on HTC One S with Android 4.1) just to list the images in the property folder (more than a minute), actually copy them This is unacceptable, because I do not take users to wait for the first minute.

The list of files I'm using the list of AssetManager class (string path) method

then I think my question is:

How to implement in a manner so that the user does not have to wait long to launch for the first time and the app will still be able to download more images on the fly?

I have a similar scenario, I zip all the files on the same zip and res / raw folder On the first startup, I have removed all the files in the internal storage of the app.

  public static zero unzipFiles (reference reference, int file) {InputStream stream; Context.getFilesDir () mkdirs () .; String path = context.getFilesDir (). GetAbsolutePath (); Try {stream = context.getResources () OpenRawResource (file); If (stream == faucet) {new runtime expiration ("can not load" + file + "file from raw folder"); } ZIP Intstream Xis = new ZIP InputStream (stream); Zip entry entry; While ((entry = zis.getNextEntry ()) = null) {if (entry.isDirectory ()) {file f = new file (path, entry.getName ()); If (! F.exists ()) {FMKDIR (); }} And {int size; Byte [] buffer = new byte [2048]; File f = new file (path, entry.getName ()); FileOutputStream fos = New FileOutputStream (f); BufferedOutputStream boss = new BufferedOutputStream (fos, buffer.length); While ((size = zis.read (buffer, 0, buffer. Album))! = -1) {Bose. Write (buffer, 0, size); } boss. Flush (); Bos.close (); }}} Hold (IOE expansion e) {new runtime expiry ("unzip" "+ + +" + "", e); }}    

No comments:

Post a Comment