0

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();
    }
  }

}
Vlad
  • 18,195
  • 4
  • 41
  • 71
  • You are only checking TAG_MAKE. What does it stand for? – blackapps Aug 20 '20 at 18:49
  • Why are you talking about sharing if you use ACTION_GET_CONTENT? What do you mean by that? The only thing i see in your code is that the user picks an image where upon some exif info is read. Further: the subject of your post does not cover it. – blackapps Aug 20 '20 at 18:52
  • @blackapps It's the make of the camera e.g. Sony. It's there as an example – Vlad Aug 21 '20 at 19:28
  • @blackapps I didn't include the part where my app can receive content from other apps because that already works correctly (e.g. I view an image in Google Photos, press share, select my app, my app receives an URI, opens it, the exif data is there); basically, what I'm curious to know is whether the code above is missing a some sort of "require original file" flag that Photos recognizes – Vlad Aug 21 '20 at 19:30

0 Answers0