Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ package io.ionic.libs.ioncameralib.helper
import android.media.ExifInterface
import android.net.Uri
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class IONCAMRExifHelper : IONCAMRExifHelperInterface {

Expand Down Expand Up @@ -203,4 +206,19 @@ class IONCAMRExifHelper : IONCAMRExifHelperInterface {
)
}

override fun setCurrentDateTime() {
// Format datetime as EXIF expects: "yyyy:MM:dd HH:mm:ss"
val currentDateTime = SimpleDateFormat(
"yyyy:MM:dd HH:mm:ss",
Locale.getDefault()
).format(Date())

outFile?.let {
it.setAttribute(ExifInterface.TAG_DATETIME, currentDateTime)
it.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, currentDateTime)
it.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, currentDateTime)
it.saveAttributes()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ interface IONCAMRExifHelperInterface {
fun getOrientation(): Int
fun resetOrientation()
fun getOrientationFromExif(exif: ExifInterface): Int
fun setCurrentDateTime()
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ class IONCAMRCameraManager(
try {
exif.createInFile(sourcePath)
exif.readExifData()

// When editing externally, the external app may write EXIF datetime in UTC.
// Fix it by writing the current local datetime back to the file.
if (camParameters.allowEdit && !intentEditedPath.isNullOrEmpty()) {
exif.createOutFile(sourcePath)
exif.setCurrentDateTime()
}
} catch (e: IOException) {
e.printStackTrace()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ class IONExifHelperMock: IONCAMRExifHelperInterface {
override fun getOrientationFromExif(exif: ExifInterface): Int {
return testOrientation
}

override fun setCurrentDateTime() {
// do nothing
}
}
Loading