i have coded an android application that will update GPS coordinates to the exif of a image file.
i think that the image file exif was updated successfully as reading it will give me the GPS coordinates saved.
However, when i open up file explorer to view the image file in details, the GPS coordinate are still showing unknown. If i restart my phone, then the exif will show the updated GPS coordinate. EDIT: if i move the file to another folder, the info will be updated as well. so meaning i must phsycially do something to the image file before it will show.
anyone have any idea why is this so? and how do i solve it so it will update immediate without going to the file explorer to move the file or restart the phone?
Thank in advance!
edit: code added for the two main part
the codes for main class
public class ShowMapActivity extends MapActivity {
ExifInterface exifInterface;
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private int Option;
private String selected_img;
float LatLong[] = new float[2];
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.gpsmaploc); // bind the layout to the activity
Bundle extras = getIntent().getExtras();
if(extras !=null) {
selected_img = extras.getString("selected_img");
Option = extras.getInt("Option",0);
}
/*Intent cancelIntent = new Intent(this, A.class);
cancelIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(cncelIntent);*/
// create a map view
RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
//mapView.setStreetView(true);
mapController = mapView.getController();
mapController.setZoom(20); // Zoon 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,
0, new GeoUpdateHandler());
updateExif(selected_img);
}
the method for updating exif
public void updateExif(String file) {
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
String address = ConvertPointToLocation(point);
String strLongitude = location.convert(location.getLongitude(), location.FORMAT_SECONDS);
String strLatitude = location.convert(location.getLatitude(), location.FORMAT_SECONDS);
String Text = "Lat=" + strLatitude + " Long=" + strLongitude;
String message = String.format(
"Current Location \n%3$s \nLongitude: %1$s \nLatitude: %2$s \n"+Text,
location.getLongitude(), location.getLatitude(),address
);
Toast.makeText(getApplicationContext(), message,
Toast.LENGTH_LONG).show();
try {
exifInterface = new ExifInterface(file);
String LATITUDE = degreeDecimal2ExifFormat(location.getLatitude());
String LATITUDE_REF = "N";
String LONGITUDE = degreeDecimal2ExifFormat(location.getLongitude());
String LONGITUDE_REF = "E";
String message2 = String.format(
"Longitude: "+ LONGITUDE + "\nLatitude: " + LATITUDE );
Toast.makeText(getApplicationContext(), message2,
Toast.LENGTH_LONG).show();
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, LATITUDE);
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, LATITUDE_REF);
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, LONGITUDE);
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, LONGITUDE_REF);
exifInterface.saveAttributes();
String exif = "";
float[] LatLong = new float[2];
if(exifInterface.getLatLong(LatLong)){
exif += "\n saved latitude= " + LatLong[0];
exif += "\n saved longitude= " + LatLong[1];
}else{
exif += "Exif tags are not available!";
}
Toast.makeText(getApplicationContext(), exif,
Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
this code seem to solve my issue.
this will refresh the sdcard content.