Q:

Choose image from image and get the directory returned

I have to launch the image gallery of Android and let the user to select an image. So I want that after the selection, the directory image is returned.
How can I do it?
Thanks.

A:

Michele,
To launch the Intent for image selection from the Gallery, use the following code:
public void imageFromGallery() {
    Intent getImageFromGalleryIntent = 
      new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    startActivityForResult(getImageFromGalleryIntent, SELECT_IMAGE);
}

Then, once the user has made their selection you get the result in onActivityResult() like so:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch(requestCode) {
            case SELECT_IMAGE:
                String imagePath = getPath(data.getData());
                break;
        }
    }

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    startManagingCursor(cursor);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

getPath() is a function to get the path from the returned URI object.  This will return a String with the path you need.
Cheers!

