Posted By

abwaters on 04/04/09


Tagged

image android


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

tartar9
claytonnarcis


Save Image to Media Provider on Android


 / Published in: Java
 

Save an image to the media library on android

  1. Uri saveMediaEntry(String imagePath,String title,String description,long dateTaken,int orientation,Location loc) {
  2. ContentValues v = new ContentValues();
  3. v.put(Images.Media.TITLE, title);
  4. v.put(Images.Media.DISPLAY_NAME, displayName);
  5. v.put(Images.Media.DESCRIPTION, description);
  6. v.put(Images.Media.DATE_ADDED, dateTaken);
  7. v.put(Images.Media.DATE_TAKEN, dateTaken);
  8. v.put(Images.Media.DATE_MODIFIED, dateTaken) ;
  9. v.put(Images.Media.MIME_TYPE, "image/jpeg");
  10. v.put(Images.Media.ORIENTATION, orientation);
  11.  
  12. File f = new File(imagePath) ;
  13. File parent = f.getParentFile() ;
  14. String path = parent.toString().toLowerCase() ;
  15. String name = parent.getName().toLowerCase() ;
  16. v.put(Images.ImageColumns.BUCKET_ID, path.hashCode());
  17. v.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name);
  18. v.put(Images.Media.SIZE,f.length()) ;
  19. f = null ;
  20.  
  21. if( targ_loc != null ) {
  22. v.put(Images.Media.LATITUDE, loc.getLatitude());
  23. v.put(Images.Media.LONGITUDE, loc.getLongitude());
  24. }
  25. v.put("_data",imagePath) ;
  26. ContentResolver c = getContentResolver() ;
  27. return c.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, v);
  28. }

Report this snippet  

You need to login to post a comment.