What I want to do:
Take a picture using my own PictureActivity* and add EXIF (geotags) data
*: Implementing SurfaceHolder.Callback
and using Camera
What is not working:
Adding the EXIF GPS data
What I've tried:
Using the ExifInterface
and manually setting Camera.Parameters
(both with the specific methods for setting GPS meta-data and by using params.set(String, Value)
).
I'm uploading the pictures to Flickr using FlickrJ (yes, I've set Flickr to import GPS data -- other pictures work fine), however this tool also says there is no GPS data in the EXIF: http://regex.info/exif.cgi
What am I missing?
(Android 2.2, HTC Desire)
Edit:
- The camera is set to Geotag photos: On
- I've tried with hardcoded dummy GPS positions
Here is the code for manually setting parameters (tried both with and without first removing the GPS data, and as mentioned also with set(String, Value)
):
@Override
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
Camera.Parameters p = mCamera.getParameters();
p.setPreviewSize(p.getPreviewSize().width, p.getPreviewSize().height);
Log.e("PictureActivity", "EXIF: "+AGlanceLocationListener.getLatitude());
p.removeGpsData();
p.setGpsLatitude( AGlanceLocationListener.getLatitude() );
p.setGpsLongitude( AGlanceLocationListener.getLongitude() );
p.setGpsAltitude( AGlanceLocationListener.getAltitude() );
p.setGpsTimestamp( AGlanceLocationListener.getTime() );
mCamera.setParameters(p);
}
Here is the code for using the ExifInterface
:
//Save EXIF location data to JPEG
ExifInterface exif;
try {
exif = new ExifInterface("/sdcard/DCIM/"+filename+".jpeg");
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
String.valueOf(AGlanceLocationListener.getLatitude()));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,
String.valueOf(AGlanceLocationListener.getLongitude()));
exif.saveAttributes();
} catch (IOException e) {
Log.e("PictureActivity", e.getLocalizedMessage());
}
Here is the code for writing the JPEG file to the SDCARD:
Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c)
{
// Bitmap pic = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
String day = String.valueOf(Calendar.getInstance().getTime().getDay());
String hour = String.valueOf(Calendar.getInstance().getTime().getHours());
String minute = String.valueOf(Calendar.getInstance().getTime().getMinutes());
String second = String.valueOf(Calendar.getInstance().getTime().getSeconds());
filename = "Billede"+day+hour+minute+second;
try {
FileOutputStream fos = new FileOutputStream(new File("/sdcard/DCIM/"+filename+".jpeg"));
fos.write(imageData);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
if(imageData != null){
Intent mIntent = new Intent();
setResult(0,mIntent);
PictureActivity.this.showDialog(0);
}
}
};
Also tried writing the image from a Bitmap
(didn't work), plus another question here report writing using a FileOutputStream
worked