I'm playing with an application that, among other things, has a button to pick images from the gallery. It then goes on to look at EXIF data from those images for additional processing.
The following scenarios work correctly, with EXIF data being read successfully:
- share photos from the Google Photos app to this app;
- using code as below, open a photo from local storage;
- using code as below, open a photo stored on Google Drive.
What doesn't work though, is using that code to open an image file provided by the Google Photos app.
The image itself shows up correctly, but the EXIF tags are missing. Note that sharing from Photos to my app does work, and there are no redaction settings turned on in the Photos app that I can see.
I'm wondering whether anyone has ever hit this issue and whether there is a workaround for it.
package com.example.somepackage;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import java.io.InputStream;
import androidx.annotation.Nullable;
import androidx.exifinterface.media.ExifInterface;
import androidx.fragment.app.Fragment;
// snippet pieced together from working code
public class SomeFragment extends Fragment {
private static final int REQUEST_PICK_FROM_GALLERY = 100;
// ............
// Called from an event handler
public void pickFromGallery() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_PICK_FROM_GALLERY);
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode) {
case REQUEST_PICK_FROM_GALLERY:
if (resultCode == Activity.RESULT_OK) {
Uri uri = data.getData();
readExifData(uri);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
private void readExifData(Uri uri) {
try (InputStream is = getContext().getContentResolver().openInputStream(uri)) {
ExifInterface exif = new ExifInterface(is);
// Do something useful.
android.util.Log.w("Test", "Camera make: " + exif.getAttribute(ExifInterface.TAG_MAKE));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}