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();
}
Try
imv.setImageURI(Uri.parse("//sdcard/img.zip!/1.png"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With