Eghes
Eghes

Reputation: 187

How to update ProgressBar for UnZip File in Android

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

Upvotes: 2

Views: 3539

Answers (2)

zulfiqar
zulfiqar

Reputation: 11

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

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007584

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.

Upvotes: 3

Related Questions