Android: Put GPSTimeStamp into jpg EXIF tags

3.9k views Asked by At

I trying to set the "GPSTimeStamp" into the exif tags of an jpg via android. The documentation is pretty scarce on this one:
http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_TIMESTAMP Type is String. Constant Value: "GPSTimeStamp". But what is the exact format?

Looking here: https://ExifTool.org/TagNames/GPS.html
GPSTimeStamp: rational64u[3] (when writing, date is stripped off if present, and time is adjusted to UTC if it includes a timezone)

So I need a long value a 3 cell array? I not sure, what to put in. I have obtained a "UTC time of this fix, in milliseconds since January 1, 1970." via location.gettime().
http://developer.android.com/reference/android/location/Location.html#getTime%28%29
If I write the long value as a string into the Timestamp and check the exif tags via "exif" on Linux, I get the error "denominator expected". All experiments with hh:mm:ss, or other formats have failed. Being a bit lost here.

1

There are 1 answers

3
bogumil On BEST ANSWER

Proper format for GPSTimeStamp attribute for sample time 14:22:32 is

"14/1,22/1,32/1"

You can use following code:

Location location = ...; // TODO - Set location properly.
long locationTome = location.getTime();
ExifInterface imageExif = new ExifInterface("absolute_path_to_image");
Calendar calendar = Calendar.getInstance();

calendar.setTimeInMillis(locationTome);
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int seconds = calendar.get(Calendar.SECOND);

String exifGPSTimestamp = hourOfDay + "/1," + minutes + "/1," + seconds + "/1";

imageExif.setAttribute("GPSTimeStamp", exifGPSTimestamp);
imageExif.saveAttributes();

It has similar format as GPSLatitude and GPSLongitude attributes. Useful explanation for such format could be also found here: http://www.ridgesolutions.ie/index.php/2015/03/05/geotag-exif-gps-latitude-field-format/