I've researched and tried numerous options to try and get this to work, but am not getting anywhere with this unfortunately.
What I am trying to do is set the Date Taken tag (Tag_DateTime) in a JPEG's Exif data from within an Android app. I already have working code to set the Latitude and Longitute tags, but cannot for the life of me get the Date taken tag to set.
Here is the code:
SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
try {
ExifInterface exif = new ExifInterface(filePhoto.getPath());
// Set and save the GPS and time data
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, strLat);
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, strLong);
exif.setAttribute(ExifInterface.TAG_DATETIME, fmt_Exif.format(locLatestLocation.getTime()));
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
I read in a post somewhere that the tag needs to be written in the milliseconds format, so have tried this too to no avail. In order to confirm my formatting with what is actually stored, I read and outputted the unformatted tag from a jpeg file which has the Date Taken tag, but the output is in exactly the same format as what I am writing to the tag and its still not working.
It might also be worth mentioning that I have looking into the Sanselan class to do this, and due to the complexity and lack of examples would much rather try and get my existing solution working before changing to a completely different one.
Has anyone managed to do this and if so what am I doing wrong??
I needed to the same thing just now.
I've read this EXIF article from MIT and I got TAG_DATETIME
to be written:
exif.setAttribute(ExifInterface.TAG_DATETIME,"2013:06:21 00:00:07");
exif.setAttribute(ExifInterface.TAG_GPS_DATESTAMP,"2013:06:21");
exif.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP,"00:00:07");
Which looked like this previewed:
Note that this in the EXIF/TIFF and GPS sections only, not the actual Original and Digitized timestamps:
I wanted to change the Original and Digitized timestamps too, so tried the JHeader library:
try {
JpegHeaders headers = new JpegHeaders(FakeBurst.PICTURE_PATH);
App1Header app1Header = headers.getApp1Header();
app1Header.setValue(new TagValue(Tag.IMAGEDESCRIPTION,"bla bla bla"));
app1Header.setValue(new TagValue(Tag.DATETIMEORIGINAL,"2013:06:21 00:00:07"));
app1Header.setValue(new TagValue(Tag.DATETIMEDIGITIZED,"2013:06:21 00:00:07"));
headers.save(true);
System.out.println(this+" wrote exif timestamp");
} catch (Exception e) {
e.printStackTrace();
}
with this added in onCreate
:
JpegHeaders.preheat();
and it worked:
I see this post is from December so maybe the Android ExifInterface code I posted above didn't work with that version of the SDK, but I'm guessing the JHeader library approach would work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With