Skip to content

Instantly share code, notes, and snippets.

@contactsunny
Created August 5, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save contactsunny/4c61b1c5493a1a5ab815 to your computer and use it in GitHub Desktop.
Save contactsunny/4c61b1c5493a1a5ab815 to your computer and use it in GitHub Desktop.
// Intent call to select image from gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
SELECT_PICTURE);
/***************************************************************/
//Handling the returned image
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
/***************************************************************/
//The getPath() function
public String getPath(Uri uri) throws NullPointerException {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment