I want to Achieve the following in my project:
- open the
Gallery
on clicking an Edittext. - select an
Image
orFile
in the gallery and get its path into my edittext.
Can anyone tell me how to do this?
I want to Achieve the following in my project:
Gallery
on clicking an Edittext.Image
or File
in the gallery and get its path into my edittext.Can anyone tell me how to do this?
On your onActivityResult
Uri uri = intent.getData();
And then grap that uri path this way
MyEditText.setText(uri.getPath());
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;
}