
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.55 KB | hits: 14 | expires: Never
downloaded images are resized automatically
private void downloadImages(String[] images, String fileName){
for (int i = 0; i < images.length; i++) {
try {
url = new URL(images[i]);
String outputName = i+fileName;
input = url.openConnection().getInputStream();
output = activity.openFileOutput(outputName, Context.MODE_PRIVATE);
int read;
byte[] data = new byte[1024];
while ((read = input.read(data)) != -1){
output.write(data, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (output != null)
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
if (input != null)
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private Drawable[] readMenuImages(){
Drawable[] drawable = new Drawable[myJSONObject.getMenuItems().length];
for(int i=0 ; i < myJSONObject.getMenuItems().length ; i++){
try {
drawable[i]=Drawable.createFromStream(activity.openFileInput(i+activity.getString(R.string.menuItemImgarabicfilename)), "ImageStream");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return drawable;
}