I need to read some Exif
properties of an Image
(taken with the Camera
or picked from the Gallery
).
Here is how I launch the Camera
:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File file = new File(myObject.getLocalUrl());
Uri fileURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI);
startActivityForResult(intent, CAPTURE_IMAGE_REQUEST_CODE);
Here is how I launch the Gallery
Picker
:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, getString(R.string.image_picker_select_image)), SELECT_IMAGE_FROM_GALLERY_REQUEST_CODE);
The problem is that for example, in the first case (Camera
), after the Image
is taken and saved in the External
Storage
, the Exif
information get lost.
The same for the Images
picked from the Gallery
. That's how I get the Image
in the onActivityResult
method:
Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
And finally here is how I read the Exif
data:
ExifInterface exifInterface = null;
try {
exifInterface = new ExifInterface(myObject.getLocalUrl());
} catch (IOException e) {
e.printStackTrace();
}
String exifOrientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
String exifMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
String exifModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL);
I've tried the next:
- Take a
picture
using my deviceCamera
(without using myApp
). - Read the
Exif
data usingExifInterface
. - It works like a charm.
So I guess the problem is that when the Image
is saved (after it's taken with the Camera
) or the Image
is picked from the Gallery
, the Exif
data gets lost.
I've read at least 20-30 post here in Stackoverflow
but basically the problem that everyone has is that the orientation
exif
information is lost, so the solution is writing the right orientation
in the Exif
data.
That solution is not fine for me since I don't want to overwrite the Exif
data, I just want to read the original one.
Any ideas/hint? Thanks.