Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a file directly from a .zip file without extracting it in android

I have been working on android for the past few months, now the problem for me is to read a .zip file placed on sdcard. I have successfully done the coding for downloading the .zip file on the sdcard.

I have img.zip file downloaded on to the sdcard. This img.zip contains 5 image files. Now instead of unzipping the img.zip can i directly read its content...??? if yes plz help. I saw few examples over internet but they all say to unzip and then use, i want to avoid that part because i simply want to set the images for an imageview.

 ImageView imv = new ImageView(this);
 imv.setImageURI(Uri.parse("//sdcard/1.png"));

this is like downloading a single image and setting the source of imv which actually works. Now what i want is something as shown below.

 imv.setImageURI(Uri.parse("//sdcard/img.zip/1.png"));

I tried this, but in my layout i don't see the images.

can it be done... plz help...

I got it working by the following code....

 try { 
                 Bitmap mBackground=null;
                    FileInputStream fis = new FileInputStream("//sdcard/tp.zip"); 
                    ZipInputStream zis = new ZipInputStream(fis); 
                    ZipEntry ze = null; 
                    while ((ze = zis.getNextEntry()) != null) { 
                        if (ze.getName().equals("1.png")) {
                            Toast.makeText(con, "Found", 2).show();
                            mBackground = BitmapFactory.decodeStream(zis);
                            imv.setImageBitmap(mBackground);
                            break; 
                        } 
                    } 
                } catch (FileNotFoundException e) { 
                    e.printStackTrace(); 
                } catch (IOException e) { 
                    e.printStackTrace(); 
                } 
like image 218
AMUL Avatar asked Dec 29 '11 05:12

AMUL


1 Answers

Try

 imv.setImageURI(Uri.parse("//sdcard/img.zip!/1.png"));
like image 69
MahdeTo Avatar answered Oct 20 '22 00:10

MahdeTo