Showing posts with label bitmap. Show all posts
Showing posts with label bitmap. Show all posts

February 20, 2010

[SOLVED] Android: Get File Path of Gallery Image



  1. // To open up a gallery browser

  2. Intent intent = new Intent();

  3. intent.setType("image/*");

  4. intent.setAction(Intent.ACTION_GET_CONTENT);

  5. startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);


  6. // To handle when an image is selected from the browser, add the following to your Activity

  7. @Override

  8. public void onActivityResult(int requestCode, int resultCode, Intent data) {


  9. if (resultCode == RESULT_OK) {


  10. if (requestCode == 1) {


  11. // currImageURI is the global variable I'm using to hold the content:// URI of the image

  12. currImageURI = data.getData();

  13. }

  14. }

  15. }


  16. // And to convert the image URI to the direct file system path of the image file

  17. public String getRealPathFromURI(Uri contentUri) {


  18. // can post image

  19. String [] proj={MediaStore.Images.Media.DATA};

  20. Cursor cursor = managedQuery( contentUri,

  21. proj, // Which columns to return

  22. null, // WHERE clause; which rows to return (all rows)

  23. null, // WHERE clause selection arguments (none)

  24. null); // Order-by clause (ascending by name)

  25. int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

  26. cursor.moveToFirst();


  27. return cursor.getString(column_index);

  28. }



Android Snippets: Get File Path of Gallery Image.