I am calling camera intent to capture an image and get the image uri in onActivtyResult in my fragment.
this is my captureImage()
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA_STORAGE);
}
this is my onActivityResult in fragment
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CAMERA_STORAGE && resultCode == RESULT_OK) {
Uri targetUri = data.getData();
String imagePath;
if (data.toString().contains(AppConstants.CONTENT)) {
imagePath = getRealPathFromURI(targetUri);
} else if (data.toString().contains(AppConstants.CONTENT)) {
imagePath = targetUri.getPath();
} else {
imagePath = null;
}
Log.d("imageuri",imagePath);
}
this getRealPathFromUri()
public String getRealPathFromURI(Uri uri) {
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(uri, proj, null, null,
null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
this works fine in one phone and in some phones, in onActivityResult data.getData() returns null.
to resolve this i came across this Capture Image from Camera and Display in Activity
but here it returns a thumbnail image. So is there any work around to get the captured image uri from camera.