Search code examples
javaandroidimageexifioexception

Saving ExifInterface tags throws IOException


I want to use Exif tags for images. It is very simple to read the tags and it works fine but saving not.

private void saveTag(String tag, String value) {
    try {
        ExifInterface exif = new ExifInterface(imagePath);
        exif.setAttribute(tag, value);
        exif.saveAttributes();
    } catch (IOException ioe) {
        toast("Image no longer exists!");
    } catch (NullPointerException npe) {
        toast("No image loaded!");
    }
}

Everytime, it throws IOException, what should I do?

granted:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Solution

  • I found out that picture must be located in device's storage when opening in Exif Interface. Have to copy picture from SD card to device's storage first.