0

I'm using ExifInterface which needs the image path to grab info like Latitude/Longitude from Uri. I can get the path of an image saved on device from Uri and send it to ExifInterface to get the details.

However, this does not work for images on Google Photos cloud. When selected from the gallery, the photo downloads automatically but ExifInterface is unable to retrieve any info since cursor.getString(index) is null.

So I try to save the image onto the storage like explained here: Getting path from Uri from Google Photos app

Then when I open the saved file using Google photos app I don't see the location details. But, if I manually save the image from the Google photos app by clicking "save" that image shows location details.

Anyway to save image details when saving an image file?

rated2016
  • 153
  • 1
  • 2
  • 12

1 Answers1

1

I'm using ExifInterface which needs the image path to grab info like Latitude/Longitude from Uri.

You could use ContentResolver and its openInputStream() method to get an InputStream on the content identified by the Uri. Then, pass that InputStream to the ExifInterface constructor.

Note that there is no requirement for an image to be in JPEG format (where EXIF tags are available) or for a JPEG image to have geotags.

When selected from the gallery, the photo downloads automatically but ExifInterface is unable to retrieve any info since cursor.getString(index) is null.

There is no requirement for a Uri that points to a piece of content, like a photo, to support anything involving a Cursor.

So I try to save the image onto the storage like explained here: Getting path from Uri from Google Photos app

You could provide the InputStream to ExifInterface and get the same result with a lot less code.

Then when I open the saved file using Google photos app I don't see the location details

It is possible that the Uri points to content that lacks the EXIF tags that you are looking for. Perhaps Google Photos holds onto that information separately, for whatever reason. That is up to the developers who created Google Photos.

It is also possible that the problem lies with how you are testing this manually.

Regardless, start by passing the InputStream directly to ExifInterface and checking the EXIF tags that way. Perhaps you will get better results.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Correct me if I am wrong but does the InputStream actually retain the EXIF data? And if the stream itself actually has the data there is the issue, that the constructor needs API 24. – MadDim Jan 11 '19 at 03:46
  • 1
    @MadDim: "Correct me if I am wrong but does the InputStream actually retain the EXIF data?" -- yes. "the constructor needs API 24" -- you are looking at the framework `ExifInterface`. Never use that, as it has security problems. Use the library `ExifInterface` (Android Support Library or AndroidX, depending on your setup). – CommonsWare Jan 11 '19 at 11:41
  • Many thanks. I never realized that there is a separate dependency. – MadDim Jan 12 '19 at 01:25