8

How to know whether the geo tagging is enabled or disabled in android camera setting through the code? We are attaching the geo tags to photos through code. We using Location Manager,Location Listener to get the latitude and longitude and save this coordinates to photo using Exif interface.

ExifInterface exif = new ExifInterface(/sdcard/photo/photoname.jpg);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,String.valueOf(latitudeValueInDecimal));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,String.valueOf(longitudeValueInDecimal));
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,"N");
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,"W");
exif.saveAttributes();

We have to add gps coordinates(latitude and longitude) to photo only when the geotag is enabled in camera setting? so how to check the status of geo tag(store location) in camera settings? I am using HTC wildfire S phone?

sondra.kinsey
  • 583
  • 7
  • 18
Praveen
  • 231
  • 1
  • 4
  • 13
  • [linked question](http://stackoverflow.com/questions/6798508/how-to-get-latitude-and-longitude-infromation-from-picture) – Anup Cowkur Oct 05 '12 at 06:32
  • possible duplicate of [How do I get the current GPS location programmatically in Android?](http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android) – AnhSirk Dasarp Sep 24 '13 at 09:46

1 Answers1

2

You can't check this programatically. You'll have to read the tags of the pictures taken and check the GPS-coordinates manually, if the tags are empty then geo-tagging is disabled.

You can use the ExifInterface class to read the EXIF metadata from JPEG images. Here's the official docs link explaining this:

http://developer.android.com/reference/android/media/ExifInterface.html

Here's sample code you can use to read the tags:

Bundle bundle = getIntent().getExtras();

if (null != bundle) {
    String filepath = bundle.getString(FILE_PATH_KEY);

    try {
        ExifInterface exif = new ExifInterface(filepath);
        StringBuilder builder = new StringBuilder();

        builder.append("Date & Time: " + getExifTag(exif, ExifInterface.TAG_DATETIME) + "\n\n");
        builder.append("Flash: " + getExifTag(exif, ExifInterface.TAG_FLASH) + "\n");
        builder.append("Focal Length: " + getExifTag(exif, ExifInterface.TAG_FOCAL_LENGTH) + "\n\n");
        builder.append("GPS Datestamp: " + getExifTag(exif, ExifInterface.TAG_FLASH) + "\n");
        builder.append("GPS Latitude: " + getExifTag(exif, ExifInterface.TAG_GPS_LATITUDE) + "\n");
        builder.append("GPS Latitude Ref: " + getExifTag(exif, ExifInterface.TAG_GPS_LATITUDE_REF) + "\n");
        builder.append("GPS Longitude: " + getExifTag(exif, ExifInterface.TAG_GPS_LONGITUDE) + "\n");
        builder.append("GPS Longitude Ref: " + getExifTag(exif, ExifInterface.TAG_GPS_LONGITUDE_REF) + "\n");
        builder.append("GPS Processing Method: " + getExifTag(exif, ExifInterface.TAG_GPS_PROCESSING_METHOD) + "\n");
        builder.append("GPS Timestamp: " + getExifTag(exif, ExifInterface.TAG_GPS_TIMESTAMP) + "\n\n");
        builder.append("Image Length: " + getExifTag(exif, ExifInterface.TAG_IMAGE_LENGTH) + "\n");
        builder.append("Image Width: " + getExifTag(exif, ExifInterface.TAG_IMAGE_WIDTH) + "\n\n");
        builder.append("Camera Make: " + getExifTag(exif, ExifInterface.TAG_MAKE) + "\n");
        builder.append("Camera Model: " + getExifTag(exif, ExifInterface.TAG_MODEL) + "\n");
        builder.append("Camera Orientation: " + getExifTag(exif, ExifInterface.TAG_ORIENTATION) + "\n");
        builder.append("Camera White Balance: " + getExifTag(exif, ExifInterface.TAG_WHITE_BALANCE) + "\n");

        builder = null;
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Renjith
  • 5,783
  • 9
  • 31
  • 42
Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • wt we are doing in our application is: geo tagging is enabled. but while continuously taking photo, then for some photos geo tags are not get attached. We tested this in 1 or 2 mobiles and confirmed that. Even though the geo tags get enabled, the geo tags are not getting attached to photos? so wt to do in this case? – Praveen Oct 05 '12 at 09:32
  • in or application, we are taking photos using camera intent.Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivityForResult(intent, Constants.ACTION_IMAGE_CAPTURE); – Praveen Oct 05 '12 at 09:45
  • You need to debug this in detail. First, Every time you attach the geotags, print them out to the logcat and check if they are being attached for every photo. Then get the tags from each photo and print them to logcat too. This will help locate the bug – Anup Cowkur Oct 05 '12 at 09:49
  • in application, we are taking photos using camera intent. We have to take photos continuously and to read the geo tags using EXIF interface and dispaly it in list view But the problem was, for some photos the geo tags are missing and Later we found that the "continuous taking of photo" fail in attaching geo tags for some photos intermediately. so we planned to attach the geo tag programatically for those photos that doesnot have geo tags. Photos doesnot have geo tag either 1) geo tag feature is disabled in camera settings or 2) geo tag failed to attach with photo so what can we do for that? – Praveen Oct 05 '12 at 11:53
  • If user has disabled geotagging then camera images wont have geotags. In that case, every time an image comes in, check if it has geotags or not, using the method I told you above. If it doesn't then display a dialog to user asking him to allow geotagging and re-run the app – Anup Cowkur Oct 05 '12 at 12:10
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17604/discussion-between-praveen-and-anup-cowkur) – Praveen Oct 05 '12 at 12:16