Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.55 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. downloaded images are resized automatically
  2. private void downloadImages(String[] images, String fileName){
  3.  
  4.     for (int i = 0; i < images.length; i++) {
  5.  
  6.         try {
  7.             url = new URL(images[i]);
  8.  
  9.             String outputName = i+fileName;
  10.  
  11.             input = url.openConnection().getInputStream();
  12.             output = activity.openFileOutput(outputName, Context.MODE_PRIVATE);
  13.  
  14.             int read;
  15.             byte[] data = new byte[1024];
  16.  
  17.             while ((read = input.read(data)) != -1){
  18.                 output.write(data, 0, read);
  19.             }
  20.  
  21.         } catch (IOException e) {
  22.             e.printStackTrace();
  23.         } finally {
  24.             if (output != null)
  25.                 try {
  26.                     output.close();
  27.                 } catch (IOException e) {
  28.                     e.printStackTrace();
  29.                 }
  30.             if (input != null)
  31.                 try {
  32.                     input.close();
  33.                 } catch (IOException e) {
  34.                     e.printStackTrace();
  35.                 }
  36.         }
  37.     }
  38. }
  39.        
  40. private Drawable[] readMenuImages(){  
  41.  
  42.     Drawable[] drawable = new Drawable[myJSONObject.getMenuItems().length];
  43.  
  44.     for(int i=0 ; i < myJSONObject.getMenuItems().length ; i++){
  45.  
  46.  
  47.         try {
  48.               drawable[i]=Drawable.createFromStream(activity.openFileInput(i+activity.getString(R.string.menuItemImgarabicfilename)), "ImageStream");
  49.  
  50.  
  51.  
  52.         } catch (FileNotFoundException e) {
  53.             // TODO Auto-generated catch block
  54.             e.printStackTrace();
  55.         }
  56.     }          
  57.  
  58.     return drawable;
  59. }