2

how can I use a determinate progressbar during the unzip process in a Android Application?

I know what I need to file has been processed to update the progressbar, but do not know how to derive this information.

Thank you!

P.S. I use to unzip the code found in this post: https://stackoverflow.com/a/7697493/1364296

Community
  • 1
  • 1
Eghes
  • 177
  • 1
  • 5
  • 18

2 Answers2

3

how can I use a determinate progressbar during the unzip process in a Android Application?

Use ZipFile to find the number of entries. Use that with setMax() on your ProgressBar to set the upper progress bound. Then, as you process each file, increment the progress by 1.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Nice and Easy, I dont know why others found it very tricky or difficult..Thanks for the direct clue. to use `ZipFile.size()` – MKJParekh Apr 30 '12 at 06:03
1

for the zip code use this .

public static void zip(String[] files, String zipFile) throws IOException {
    BufferedInputStream origin = null;
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
    try { 
        byte data[] = new byte[BUFFER_SIZE];

        for (int i = 0; i < files.length; i++) {
            FileInputStream fi = new FileInputStream(files[i]);    
            origin = new BufferedInputStream(fi, BUFFER_SIZE);
            try {
                ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
                out.putNextEntry(entry);
                int count;
                while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                    out.write(data, 0, count);
                }
            }
            finally {
                origin.close();
            }
        }
    }
    finally {
        out.close();
    }
}

try to use buffer when zip on unzip because it will be much faster

Spudley
  • 166,037
  • 39
  • 233
  • 307
zulfiqar
  • 11
  • 3