0

I am desiging an android program to change LatLng of images. Images Uri is in an Array the code is as follows

Exception that occurs says "ExifInterface does not support saving attributes for the currrent input"

    InputStream in = getContentResolver().openInputStream((Uri)AddArray[i]);

    ExifInterface ei = new ExifInterface(in);

    ei.setAttribute(TAG_GPS_LATITUDE, "80/1,35/1,4091/100");
    ei.setAttribute(TAG_GPS_LATITUDE_REF, "N");
    ei.setAttribute(TAG_GPS_LONGITUDE, "45/1,1/1,4390/100");
    ei.setAttribute(TAG_GPS_LONGITUDE_REF, "E");



    try {
        ei.saveAttributes();
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();

    }


} catch (IOException e) {
    Toast.makeText(getApplicationContext(), "Something went wrong" + e.getMessage(), Toast.LENGTH_LONG).show();
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

ExifInterface, as you are using it, only has an InputStream, and so it has no way of persisting your changes.

You would need to:

  • Use the InputStream to make a copy of the content identified by that Uri to some file that you control (e.g., in getCacheDir())

  • Use ExifInterface with that file, saving changes to that file

  • Use openOutputStream() on ContentResolver to get an OutputStream on the content identified by the Uri, then copy the bytes of the file to that OutputStream

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • can u please elaborate this line: Use the InputStream to make a copy of the content identified by that Uri to some file that you control (e.g., in getCacheDir()) – Abdullah Mufti Dec 29 '17 at 16:40
  • @AbdullahMufti: `InputStream` is part of `java.io`. You use it to read in data from some source (file, HTTP response, etc.). You can create a `FileOutputStream` on some file that you control, and use standard Java I/O to copy the bytes from the `InputStream` to the `FileOutputStream`. When you are done, you have a file that contains the same data as whatever the `Uri` points to. Now, you can use `ExifInterface` with that file, and `ExifInterface` can save to the file. – CommonsWare Dec 29 '17 at 16:48
  • One Last Favor : Can u please identify the mistake in my code InputStream in = getContentResolver().openInputStream((Uri)AddArray[i]); File myFile=getCacheDir(); File outFile=new File(myFile, String.valueOf(in)); OutputStream os = new FileOutputStream(outFile.getAbsolutePath()); – Abdullah Mufti Dec 29 '17 at 17:52
  • @AbdullahMufti: I do not know why you are trying to name your file something like `InputStream@f384d304`, which is what I would expect `String.valueOf(in)` to return. You can pass the `File` directly to `new FileOutputStream()` without the `getAbsolutePath()`. And you have no code here to copy data between the streams. Java I/O is covered in many books and courses on Java programming. Or, search `java copy input stream to outputstream` in your favorite search engine for solutions [like this](https://stackoverflow.com/a/40019374/115145). – CommonsWare Dec 29 '17 at 18:00