Android Question [Solved] How I can get the date/time a web file before download it?


Well-Known Member
Licensed User
Longtime User
I want to download a file (html/xml) but before the download, I want to check if the file is newer than the last file that I downloaded.

How can I check it?

Thanks in advance for any tip.


Licensed User
Longtime User
If it is your Webserver and your files then you could use a php script for example which returns the dates of files

header("content-type: text/plain");
$result = array();

foreach (glob('/absolute/path/to/images/*.png') as $filename) {
    $thisfile = array();

    $path_parts = pathinfo($filename);

    $thisfile["filename"] = $path_parts['basename'];
    $thisfile["ext"] = $path_parts['extension'];
    #echo $filename." - Größe: " . filesize($filename) . "\n";
    $size = getimagesize( $filename);
  $thisfile["width"] = $size[0];
  $thisfile["height"] = $size[1];
  # echo "Bildbreite: " . $size[0];
  # echo "Bildhöhe: " . $size[1];
  $result[] = $thisfile;
echo json_encode($result);

Upvote 0


Licensed User
Longtime User
I was thinking if is possible to use a library like httputils and informe the url and get the timestamp of the file.
You can use httputils for this.

BUT the server must implement a method which returns the filedate.

My php above is just an example you can easily adapt to not check the imagessizes but to check the filedate and then return it.
Upvote 0


Well-Known Member
Licensed User
Longtime User
I tried to use the code below, but I get the date = 01/17/1970 in all dates.

Where I am going wrong?
How to fix to display the date of the file?

Thanks for any tips to correct and improve the code.

Sub Activity_Create(FirstTime As Boolean)
    Dim job1 As HttpJob
    job1.Initialize("Job1", Me)
    'Send a GET request
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
           Dim res As String
        res = Job.GetString
        Dim parser As JSONParser

        Select Job.JobName
            Case "Job1"
                   Dim ListOfAttributes As List
                Dim FileName As String
                Dim FileDate As Long
                ListOfAttributes = parser.NextArray 'returns a list with maps
                For i = 0 To 5
                    Dim MyFiles As Map
                    MyFiles = ListOfAttributes.Get(i)
                    FileName = MyFiles.Get("filename")
                    FileDate = MyFiles.Get("mtime")
                    Log(FileName & " - " & " - " & DateTime.Date(FileDate))  'date = 01/17/1970       
        End Select
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
End Sub
Upvote 0