Skip to content Skip to sidebar Skip to footer

Best Way To Download Images From Xml Content

I am designing an Android application which will be displaying some news that will be retrieved from a remote URL in xml format, say http://adomain/latest.xml The XML file has the

Solution 1:

I recommend lazy loading as the news item is displayed, so you don't use excessive bandwidth (and potentially cost for the user). No point in downloading images if the user never wants to look at them.

Solution 2:

for images, I think you always follow lazy loading because, image loading may take some time, and also an efficient lazy loader can help you to avoid any future memory issue.

Solution 3:

Just fetch <Image> tag data from your XMl.

StringimgURL= your <Image> value;  

 ImageViewimageView=newImageView(this);

                Bitmapbmp= BitmapFactory.decodeStream(newjava.net.URL(imgURL).openStream());

                    imageView.setId(i);
                    imageView.setImageBitmap(bmp);

This will work to set image and you also get image in "bmp".

Android provide directly show image from URL:

For Store Image to Sd Card:

File file = new File (pathOfSdCard, iamgeName);

try {                      
    file.createNewFile();
    FileOutputStream out = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 10, out);
                out.flush();
                out.close();

    } catch (Exception e) {
                e.printStackTrace();
    }

Put Line to your AndroidMenifest:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />

This all i using in my app. it works fine.

I hope this will helps you a lot.

Post a Comment for "Best Way To Download Images From Xml Content"