Pages

Friday, 13 September 2013

To download the images device local storage from internet



if(ImageUrl.length()>0){
File file=new File(directory,filename);
if(file.exists()&&file.length()==0){
file.delete();
}
if(!file.exists()){
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(new URL(ImageUrl).openStream());
bitmap.compress(CompressFormat.JPEG, 50, ostream);
ostream.flush();
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

No comments:

Post a Comment