I am using the default camera intent to get the image in my app. The problem is camera returns null on onActivityResult()
. The ResultCode
and RequestCode
are returning as expected.
My intent call is:
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1224;
....
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
OnactivityResult is:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
//use imageUri here to access the image
Uri imageuri = data.getData(); // here is getting crash
imageView.setImageFromUri(imageUri);
}
}
}
void setImageFromUri(Uri imgUri){
... TODO assign image from uri
}
As I put Log I got the resultCode and responseCode are not null
resultCode = -1
requestCode = 1224
Where I am doing mistake?
But the taken picture is stored in the path (imageUri) as I specified
Is there any other way to get image using camera.
Seems you know the imageUri before onActivityResult. This is not correct answer but will work fine.
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
// This image uri only you're going to use
So don't use
Uri imageuri = data.getData();
just use the uri you known.
your code looks like this:
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
//use imageUri here to access the image
imageView.setImageFromUri(imageUri); // imageUri should be global in the activity
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With