0

I want to Achieve the following in my project:

  1. open the Gallery on clicking an Edittext.
  2. select an Image or File in the gallery and get its path into my edittext.

Can anyone tell me how to do this?

JRE.exe
  • 801
  • 1
  • 15
  • 28
  • @Nikka - not sure why your edit was approved, especially since, while attempting to clean up grammar, you actually introduced an error. – David Makogon May 16 '14 at 02:14

2 Answers2

0

On your onActivityResult
Uri uri = intent.getData();
And then grap that uri path this way MyEditText.setText(uri.getPath());

Kosh
  • 6,140
  • 3
  • 36
  • 67
0

try this,

For open gallary,

Intent intent = new Intent();
                            intent.setType("image/*");
                            intent.setAction(Intent.ACTION_GET_CONTENT);
                            startActivityForResult(Intent.createChooser(intent, ""), PICK_IMAGE);

use this method to get image path,

@SuppressWarnings("unchecked")
    @Override
    protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {

                case PICK_IMAGE:

            String imagepath =  (getAbsolutePath(data.getData()) + "|").split("\\|");
                    break;
            }
        }
    }


public String getAbsolutePath(Uri uri) {
        String[] projection = { MediaColumns.DATA };
        @SuppressWarnings("deprecation")
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if (cursor != null) {
            int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } else
            return null;
    }
Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19