Android escribe EXIF ​​GPS Latitude and Longitude en JPEG fallado

Me gustaría agregar datos de GPS como la longitud y la latitud en la foto jpeg. La foto se captura al tabular la tarjeta (NFC) En el logcat, se pueden mostrar los valores correctos, ¡pero estos valores no se pueden escribir en el archivo de fotos jpg!

A continuación se encuentra mi código: se usa para tomar archivos jpg guardados y llamar al método que se encuentra a continuación. Se usa el método para agregar parámetros GPS EXIF ​​en el jpg Los parámetros GPS, como la longitud y la latitud, ya se toman en otra actividad.

Uso EXIF ​​Viewer en Firefox para ver el resultado.

¿Importa la posición para la excepción IO?

El siguiente es el registro de registro cat importante que puede generar el error: 07-26 11: 48: 30.386: D / NativeNfcTag (195): etiqueta perdida, reinicio del bucle de sondeo

 public static void writeFile (File photo, double latitude, double longitude) throws IOException{


    ExifInterface exif = null;

    try{
        Log.v("latiDouble", ""+latitude);
        Log.v("longiDouble", ""+longitude);
        exif = new ExifInterface(photo.getCanonicalPath());
        if (exif != null) {
        double latitu = latitude;
        double longitu = longitude;
        double alat = Math.abs(latitu);
        double along = Math.abs(longitu);
        String stringLati = convertDoubleIntoDegree(alat);
        String stringLongi = convertDoubleIntoDegree(along);
        exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, stringLati);            
        exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, stringLongi);
        Log.v("latiString", ""+ stringLati);
        Log.v("longiString", ""+ stringLongi);
        exif.saveAttributes();
        String lati = exif.getAttribute (ExifInterface.TAG_GPS_LATITUDE);  
         String longi = exif.getAttribute (ExifInterface.TAG_GPS_LONGITUDE);  
         Log.v("latiResult", ""+ lati);
         Log.v("longiResult", ""+ longi);

        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }

}

La siguiente es la posición para llamar al método ...

    Cursor locationCursor = dbHandler.fetchGpsLocationTypeByAttendInfoID(attendInfoId);
      if (locationCursor.getCount()>0) {
        double latitude = dbHandler.fetchDoubleItem(locationCursor,"LATITUDE");
        double longitude = dbHandler.fetchDoubleItem(locationCursor,"LONGITUDE");


            Log.v("latitude",""+latitude);
            Log.v("latitude",""+longitude);     

            try {
                GpsUtils.writeFile(photoFile, latitude, longitude);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

    }
    dbHandler.close();

    cameraHandler.startPreview();

Respuestas a la pregunta(1)

Su respuesta a la pregunta