Friday, October 21, 2011

Android Save Image to Media Provider


public Uri saveMediaEntry(String imagePath,String title,String description,long dateTaken)
{
ContentValues image = new ContentValues();

image.put(Images.Media.TITLE, "ImageTitle");
image.put(Images.Media.DISPLAY_NAME, "Heart");
image.put(Images.Media.DESCRIPTION, "description");
image.put(Images.Media.DATE_ADDED, dateTaken);
image.put(Images.Media.DATE_TAKEN, dateTaken);
image.put(Images.Media.DATE_MODIFIED, dateTaken);
image.put(Images.Media.MIME_TYPE, "image/jpeg");
image.put(Images.Media.ORIENTATION, 0);
File imageFile = new File(imagePath) ;
File parent = imageFile.getParentFile();
String path = parent.toString().toLowerCase();
String name = parent.getName().toLowerCase();
image.put(Images.ImageColumns.BUCKET_ID, path.hashCode());
image.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name);
image.put(Images.Media.SIZE, imageFile.length());
image.put("_data", imageFile.getAbsolutePath());
return getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, image);
}



No comments:

Post a Comment