Skip to content Skip to sidebar Skip to footer

Get Image Uri In Onactivityresult After Taking Photo?

I have this code: startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA_IMAGE); That allows that user to take a photo. Now how would I get the Uri of that pho

Solution 1:

protectedvoidonActivityResult(int requestCode, int resultCode, Intent intent){
    Uriu= intent.getData();
}

By the way... there's a bug with that intent in some devices. Take a look at this answer to know how to workaround it.

Solution 2:

Instead of just launching the intent, also make sure to tell the intent where you want the photo.

Uriuri= Uri.parse("file://somewhere_that_you_choose");
IntentphotoIntent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(photoIntent, CAMERA_IMAGE);

Then when you get your onActivityResult() method called, if it was a success just open a stream to the URI and it should all be set.

Solution 3:

Uriuri=null;
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
  uri = data.getData();
}

Solution 4:

protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {

          Bitmapphoto= (Bitmap) data.getExtras().get("data");
          UrifileUri= Utils.getUri(getActivity(), photo);
    }  
}

public String getRealPathFromURI(Uri contentUri) {
    Stringpath=null;
    String[] proj = { MediaStore.MediaColumns.DATA };
    Cursorcursor= getActivity().getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor.moveToFirst()) {
        intcolumn_index= cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
        path = cursor.getString(column_index);
    }
    cursor.close();
    return path;
}

Post a Comment for "Get Image Uri In Onactivityresult After Taking Photo?"