-1

Possible Duplicate:
How to load image from url

I want to know how to load image from URL and save in local database.

Pls help me

Thanks Monali

Community
  • 1
  • 1
Monali
  • 1,966
  • 12
  • 39
  • 59
  • 1
    please specify your answer - what exactly do you want to do, what have you tried to so far, etc.. – Blitz Jun 13 '11 at 13:56

2 Answers2

2

-You might find some help in loading the image from a URL in:

How to load an ImageView by URL in Android?

-As for saving it, this may be useful:

Save bitmap to location

Community
  • 1
  • 1
Matt
  • 5,404
  • 3
  • 27
  • 39
1

To do this, you should use the MediaStore API

String yourImageFilename= String.valueOf(System.currentTimeMillis()); //using this for simplicity

ContentValues cValues = new ContentValues();   
cValues.put(Images.Media.TITLE, yourImageFilename);
cValues.put(Images.Media.DATE_ADDED, System.currentTimeMillis()); 
cValues.put(Images.Media.MIME_TYPE, "image/jpeg"); //your image type here, jpg for sample

Uri uri = context.getContentResolver().insert(Images.Media.INTERNAL_CONTENT_URI, values);

try {

  OutputStream outStream = context.getContentResolver().openOutputStream(uri);
  Url imageResource = new Url("your url string");
  Bitmap mBitmap = BitmapFactory.decodeStream(imageResource.openStream());

  mBitmap.compress(Bitmap.CompressFormat.JPEG, 90, outStream); //if you want to compress the jpg

  outStream.flush();
  outStream.close();

} catch (FileNotFoundException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

I am assuming you mean in the local database(viewable by the gallery, if not then please edit your question to be more specific).

hwrdprkns
  • 7,525
  • 12
  • 48
  • 69