Android Library that makes it easy to download images with a simple and straight forward API.
VutaImage is an Android library that makes the work of downloading images from a URL to the device's SDCARD pretty much easy with a very simple and straight forward API.
At a glance
final String imageUrl = "http://myexample.com/img/sample1.png"; VutaImage.download( imageUrl, new ImageDownloadCallback() { @Override public void progress(int elapsed, int totalSize) { Log.e( TAG , "Image download progress = "+elapsed+" out of "+totalSize ); } @Override public void done(boolean success) { Log.e( TAG , "Image download done with success = "+success ); } });
Download the latest jar file from VutaImage_Jar_1.0
Download VutaImage project from the github project page https://github.com/bmutinda/VutaImage, import VutaImage-Library to your workspace as an Android Project. Once the project has been imported successfully,
Remember to add these permissions to your Android project
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Lets see how to use VutaImage to download images
You can download an image without specifying the destination filename and the library with automatically resolve the filename from the supplied link. For instance, downloading an image from
, the downloaded image will be saved with the name in the default storage location - which is thefinal String imageUrl = "http://myexample.com/img/sample1.png"; VutaImage.download( imageUrl, new ImageDownloadCallback() { @Override public void progress(int elapsed, int totalSize) { Log.e( TAG , "Image download progress = "+elapsed+" out of "+totalSize ); } @Override public void done(boolean success) { Log.e( TAG , "Image download done with success = "+success ); } });
NB: The destination filename must be the complete path together with the directory.
final String imageUrl = "http://myexample.com/img/sample1.png"; String sdCard = VutaImage.getExternalStorage( ); String filename = sdCard+"/file.png"; VutaImage.download( imageUrl, filename, new ImageDownloadCallback() { @Override public void progress(int elapsed, int totalSize) { Log.e( TAG , "Image download progress = "+elapsed+" out of "+totalSize ); } @Override public void done(boolean success) { Log.e( TAG , "Image download done with success = "+success ); } });
You can use an instance of the VutaImageItem as a parameter to download the image
String sdCard = VutaImage.getExternalStorage( ); VutaImageItem vutaImageItem = new VutaImageItem( "http://domain.com/img.png", sdcard+"/image.png" ); VutaImage.download( vutaImageItem, new ImageDownloadCallback() { @Override public void progress(int elapsedSize, int totalSize) { Log.e("TAG_", "iMAGE progress --- "+elapsedSize+" out of ->"+totalSize ); } @Override public void done(boolean success) { Log.e("TAG_", "iMAGE done with status --- "+success ); } });
Define a list of all the images you want to download using the VutaImageItem class as follows
// Get the sdcard directory String sdcard = VutaImage.getExternalStorage(); // Create a list of all the images we want to download Listimages = new ArrayList (); images.add( new VutaImageItem("http://myexample.com/img/sample1.png", sdcard+"/img.png" )); images.add( new VutaImageItem("http://myexample.com/img/sample2.png", sdcard+"/Logo1.png" )); images.add( new VutaImageItem("http://myexample.com/img/sampl23.png", sdcard+"/Logo2.png" ));
With multiple images download, there are two callbacks you can use
VutaImage.download(images, new EachImageDownloadCallback() { @Override public void onProgress(VutaImageItem image, boolean success) { Log.e(TAG, "Image downloads progress.."+image.getUrl()+"->success = "+success ); } @Override public void onError(VutaImageItem image) { Log.e(TAG, "Image failed to download.."+image.getUrl() ); } @Override public void done() { Log.e(TAG, "All images downloaded" ); } });
VutaImage.download(images, new ImagesDownloadCallback() { @Override public void onError(VutaImageItem image) { Log.e(TAG, "Image failed to download..."+image.getUrl()+"->"+image.getFilename() ); } @Override public void done() { Log.e(TAG, "All images downloaded" ); } });
You can set the default storage location for the downloaded images in cases where you are supplying only the image url. For instance, in this case
VutaImage.download("http://myexample.com/img/sample1.png", new ImageDownloadCallback() { ...... });The image is downloaded to the default storage which is the .
VutaImage.setDefaultStorageDir( "/my/dir/path/")
To get the set default location, use the method below:
VutaImage.getDefaultStorageDir()NB: If you don't call the , the default storage will be the root of the sdcard.
Called during the download progress of a single image
// The first parameter(elapsed) holds the total file size already downloaded in KB // Second parameter (totalSize) - Is the file total size in KB @Override public void progress(int elapsed, int totalSize) { .... }
Called during the download of multiple images after one image has been downloaded fully or an error occurred while downloading.
// First parameter -image - represents the
instance of the image downloaded
// Second parameter - success - tells whether the download went on ok (True) or an error occurred (False)
@Override
public void onProgress(VutaImageItem image, boolean success) { .... }
Called if an error is encountered during the download process of multiple images
NB: This method is triggered just before
// First parameter -image - represents the
instance of the image that failed
@Override
public void onError(VutaImageItem image) { .... }
Called when the download is fully completed with or without errors for a single image download
// success - True if everything was downloaded without error // - False if an error occurred during download process @Override public void done( boolean success) { .... }
Called when the download is fully completed with or without errors for multiple images download
@Override public void done() { .... }
Clone the project from the GitHub page, work on your changes then submit a pull-request and I will review and merge to the main branch for the next release
Feel free to submit any issues about the library on the GitHub project issues page
Need to propose a feature or need to say something? Drop me an email at
with the subject VutaImage Library