Save image to gallery problem

+1 Roman Smirnov · February 23, 2015
Hi guys,

I tried using the below method to add a bitmap to my phone's gallery. 
MediaStore.Images.Media.insertImage(getContentResolver(), newPhoto, "title", "description");
Added the permission <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The image doesn't get added to the gallery, nor does it appear in any place I can figure out on the device.
the method returns the String content://media/external/images/media/19990 as String.
My code http://www.codeshare.io/uV2c7
Any ideas?

Post a Reply

Replies

Oldest  Newest  Rating
+2 Mike Lupo · February 24, 2015
As "jimmithy" had said, 


"You need to define DATE_TAKEN when inserting the image. This can be done by altering the way you add images to the gallery, and doing something like the following:


ContentValues values = new ContentValues();
   values.put(Media.TITLE, title);
   values.put(Media.DESCRIPTION, description); 
   values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
   values.put(Images.Media.MIME_TYPE, "image/jpeg");
   values.put(MediaStore.MediaColumns.DATA, filepath);

   getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);



If you need any other pointers, I would take a look at MediaStore.Images.Media.insertImage"




I hope this helped.
+1 Roman Smirnov · February 26, 2015
Thanks man, much appreciated
  • 1

Java / Android Development

107,083 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator