how to use getLastModified() in android for XML file creation/modicfication date check
-
29-09-2019 - |
Question
I am parsing XML file in my android application, but I like to modify the code, that it only parses the XML file if it is update (I will store the last successful parse date).
I found out the
urlConnection.getLastModified();
but not getting proper idea of how to use it, as it is returning milliseconds as long. is it possible I can check if file is modified or not.
thanks in advance.
Solution
You can use that timestamp to determine when the file was last modified. If that time is newer than the last-modified timestamp value from your last parse, the file probably was modified, so re-parse it.
Even better would be to use If-Modified-Since
headers in your HTTP request, so you can skip the HTTP download of the file if it has not been modified since your last parse.