I used startActivityForResult
to pick a picture from gallery and then used onActivityResult
for bring the result.
when i use getPath()
for the intent result to send the path to another activity to set the source of that picture , the path is incorrect and is another way that the picture is not located there .
the picture is located in sdcard and located at : "mnt/sdcard/pictures/lambo"---- but getpath()
his returns : "external/images/media/17
photopicker :
private void photopicker() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PHOTO);
}
onActivityResult :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String add;
add = selectedImage.getPath(); // don't work
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
selectedPhoto = BitmapFactory.decodeStream(imageStream);
// add = selectedImage.getPath(); // don't work
Intent intent = new Intent(MainActivity.this, PicViewer.class);
intent.putExtra("add", add);
startActivity(intent);
}
}
}