I have an app in which I visualize metadata of some photos that I've taken and I can edit the location using a Place Picker
and update the exif data using the following code:
ExifInterface exifInterface = null;
try {
exifInterface = new ExifInterface(imageFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
if(exifInterface != null) {
try {
exifInterface.setLatLong(place.getLatLng().latitude,place.getLatLng().longitude);
exifInterface.saveAttributes();
sendBroadcastToUpdateMediaFile();
Log.v(TAG,"Updating with: "+place.getName());
} catch (IOException e) {
e.printStackTrace();
}
}
The data does get the update because if I close the app and open it again and visualize the Exif data I can see the new location being there, but if I go inside the gallery and click details on the same image the location is not there. The photo format is jpeg/jpg, as only those types can have exif data(I get an error when trying to add exifdata on png for example).
Why is the exif data from the same image inside the gallery not get updated? What am I doing wrong?
Edit:
Solution:
private void sendBroadcastToUpdateMediaFile(){
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(imageFile.getAbsolutePath());
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}