Android Copy EXIF Data (Kotlin)

Jun 18, 2018
fun copyExif(oldPath: String, newPath: String) {    val oldExif = ExifInterface(oldPath)    val attributes = arrayOf(            // ExifInterface.TAG_APERTURE,            ExifInterface.TAG_APERTURE_VALUE,            ExifInterface.TAG_DATETIME,            ExifInterface.TAG_DATETIME_DIGITIZED,            ExifInterface.TAG_DATETIME_ORIGINAL,            ExifInterface.TAG_EXPOSURE_TIME,            ExifInterface.TAG_FLASH,            ExifInterface.TAG_FOCAL_LENGTH,            ExifInterface.TAG_GPS_ALTITUDE,            ExifInterface.TAG_GPS_ALTITUDE_REF,            ExifInterface.TAG_GPS_DATESTAMP,            ExifInterface.TAG_GPS_LATITUDE,            ExifInterface.TAG_GPS_LATITUDE_REF,            ExifInterface.TAG_GPS_LONGITUDE,            ExifInterface.TAG_GPS_LONGITUDE_REF,            ExifInterface.TAG_GPS_PROCESSING_METHOD,            ExifInterface.TAG_GPS_TIMESTAMP,            // ExifInterface.TAG_IMAGE_LENGTH,            // ExifInterface.TAG_IMAGE_WIDTH,            ExifInterface.TAG_ISO,            ExifInterface.TAG_ISO_SPEED_RATINGS,            ExifInterface.TAG_MAKE,            ExifInterface.TAG_MODEL,            ExifInterface.TAG_ORIENTATION,            ExifInterface.TAG_SUBSEC_TIME,            ExifInterface.TAG_SUBSEC_TIME_ORIGINAL,            ExifInterface.TAG_SUBSEC_TIME_DIGITIZED,            // ExifInterface.TAG_SUBSEC_TIME_DIG,            // ExifInterface.TAG_SUBSEC_TIME_ORIG,            ExifInterface.TAG_WHITE_BALANCE)    val newExif = ExifInterface(newPath)    for (i in attributes.indices) {        val value = oldExif.getAttribute(attributes[i])        if (value != null)            newExif.setAttribute(attributes[i], value)    }    newExif.saveAttributes()}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.