android-10.0android-exifinterface

How to edit exif in android Q


I want to create an jpg and edit its exif.
Before, I use ExifInterface:

ExifInterface exifInterface = new ExifInterface(filePath)
exifInterface.setAttribute(...)
exifInterface.setAttribute(...)
exifInterface.saveAttributes();

But in Android Q, I just got a image uri from MediaStore API instead of a file path.I try to use this:

new ExifInterface(inputStream)

But when I call saveAttributes() ,it shows like this

java.io.IOException: Failed to copy original file to temp file

So,is there another way to deal with this problem


Solution

  • I had the same issue. I solved it by updating ExifInterface to 1.3.1 in build.gradle (app):

    implementation 'androidx.exifinterface:exifinterface:1.3.1'
    

    Seems to be related with this commit to saveAttributes, as indicated in the release notes: https://developer.android.com/jetpack/androidx/releases/exifinterface#1.3.1

    Fix saveAttributes implementation to keep the image data in MediaProvider