I'm trying to write lat-long and other data to the Exif header of a jpeg in my custom camera app. Typically android automatically populates the header with data such as aperture, ISO, shutter speed etc. However, when I manually add create an ExifInterface
instance, set the GPS location with SetAttributes()
, and call SaveAttributes()
; all of the other camera data dissapears.
Is this supposed to happen? How can I simply add a tag without overwriting everything else?
I saw an example elsewhere of creating two ExifInterfaces, an old(from the picture) and a new, and copying every populated value from the old to the new along with any other data. This however, is annoying and lengthy. I would like to find a better solution.
Here is my code:
try{
ExifInterface exif = new ExifInterface(pictureFile.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, mGpsLocation.getLatDms());
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, mGpsLocation.getLonDms());
exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, mGpsLocation.getAltDms());
exif.saveAttributes();
} catch(IOException e){
e.printStackTrace();
}
Thanks