Android Question httputils2 not updated download file

tucano2000

Active Member
Licensed User
Longtime User
I'm having trouble to download an image file (.gif) HttpUtils2 using:

http://www.b4x.com/android/forum/threads/download-huge-files-with-httputils2.30220/

The download process is fine, but if I change the file image with one with the same name, the download stays with the previous picture.

I deleted the file from the cache directory but I had no success.

I found that by changing the ip of my connection in android changing operator or wifi the image changes to the new file that has the same name.

I need to use banner in my app and I only change the image file on FTP for customers to receive the new image. All this without changing the file name and just rewriting the same file with a new image in the FTP.

Because the download remains of the previous file if I already went to the site and changed the image? It is possible to solve this?
 

sorex

Expert
Licensed User
Longtime User
Upvote 0

tucano2000

Active Member
Licensed User
Longtime User
Thanks Sorex but I am using a static link and I think that your suggestion does not solve my problem...
 
Last edited:
Upvote 0

tucano2000

Active Member
Licensed User
Longtime User
Can you post the relevant code?

I switch image1.gif ftp site but the image shown in the application is always equal to the previous. If the application is uninstalled and installed in order to erase the cache the problem remains.

To test I went on ftp site and changed the picture with another with the same name.

I would like to exchange image1.gif by another figure with the same name and the application to show the change.

But this fact only occurs when I change my ip or internet provider

Erel see my code (this code may to use HttpUtils2 library):

B4X:
#Region  Project Attributes
    #ApplicationLabel: Banner Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #DebuggerForceStandardAssets: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim TimerBanner As Timer
End Sub

Sub Globals
    Dim gif As GifDecoder
    Dim ImageViewAds As ImageView
    Dim BannerLink As String
    Dim Frame As Int
    Dim JobTipo As String
    Dim JobStatus As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ImageViewAds.Initialize("ImageViewAds")
    Activity.AddView(ImageViewAds,0dip, 100%y-50dip, 320dip, 50dip)
    gif.DisposeFrames
    TimerBanner.Initialize("TimerBanner",0)
    Dim Job1 As HttpJob
    Job1.Initialize("Job1", Me)
    Job1.Download("http://aldinformatica.com/banner/link1.txt")
End Sub

Sub Activity_Resume
    If File.Exists(File.DirInternal,"image1.gif") Then
        Frame=0
        gif.load(File.DirInternal,"image1.gif")
        TimerBanner.Interval = gif.Delay(Frame)
        TimerBanner.Enabled=True
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If TimerBanner.IsInitialized Then TimerBanner.Enabled = False
End Sub

Sub JobDone (Job As HttpJob)
  If Job.Success = True Then
      Select Job.JobName
          Case "Job1"
            Dim Link As String
            File.Copy(File.DirInternalCache,"1",File.DirInternal,"link1.txt")
            BannerLink=File.ReadString(File.DirInternal,"link1.txt")
            If BannerLink.Contains("http://") OR BannerLink.Contains("market://") Then JobStatus=True Else JobStatus=False
            Dim Job2 As HttpJob
              Job2.Initialize("Job2", Me)
       
            'I changed image1.gif in ftp site
            Job2.Download("http://aldinformatica.com/banner/image1.gif")

        Case "Job2"
            File.Copy(File.DirInternalCache,"2",File.DirInternal,"image1.gif")
            gif.load(File.DirInternal,"image1.gif")
            Frame = 0
            TimerBanner.Interval = gif.Delay(Frame)
            Log(TimerBanner.Interval)
            ImageViewAds.Bitmap = gif.Frame(Frame)
            ImageViewAds.Gravity = Gravity.FILL
            TimerBanner.Enabled = True
      End Select
  Else
      Log("Error: " & Job.ErrorMessage)
  End If
End Sub
Sub ImageViewAds_Click
    If JobStatus Then
        If BannerLink.Contains("market://") Then
            Dim UriStr As String = BannerLink
            Dim Market As Intent
              Market.Initialize(Market.ACTION_VIEW,UriStr)
        Else
            Dim pp1 As PhoneIntents
            StartActivity(pp1.OpenBrowser(BannerLink))
        End If
    End If
End Sub

Sub TimerBanner_Tick
    TimerBanner.Enabled = False
    Frame = Frame + 1
    If Frame >= gif.FrameCount Then
        Frame = 0
    End If
    'TimerBanner.Interval = gif.Delay(Frame)
    ImageViewAds.Bitmap = gif.Frame(Frame)
    TimerBanner.Enabled = True
End Sub
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
static or not doesn't matter, the randomizer tricks the cache part as it tries to load an url that's not loaded before.

B4X:
Dim r AsInt = Rnd(0,999999)
Job2.Download("http://aldinformatica.com/banner/image1.gif?r="&r)
 
Upvote 0

tucano2000

Active Member
Licensed User
Longtime User

Thanks! Now I understood. You are right. I made the modification you said and now works perfectly:

B4X:
    'I changed image1.gif in ftp site and image
    Dim r As Int = Rnd(0,999999)
    Job2.Download("http://aldinformatica.com/banner/image1.gif?r=" & r)


And I added this code to avoid the error when the timer tries to load an image with the download not finished:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Added code  ----------------------------------------
    If File.Exists(File.DirInternal,"link1.txt") Then
        File.Delete(File.DirInternal,"link1.txt")
    End If
    If File.Exists(File.DirInternal,"image1.gif") Then
        File.Delete(File.DirInternal,"image1.gif")
    End If
    '----------------------------------------------------

    ImageViewAds.Initialize("ImageViewAds")
    Activity.AddView(ImageViewAds,0dip, 100%y-50dip, 320dip, 50dip)
    gif.DisposeFrames
    TimerBanner.Initialize("TimerBanner",0)
    Dim Job1 As HttpJob
    Job1.Initialize("Job1", Me)
    Job1.Download("http://aldinformatica.com/banner/link1.txt")
End Sub

Excellent but now came a question of why this occurs. Http or HttpUtils2 library not have a clear cache method ? I did not found.
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
Maybe it uses standard system calls where the caching is used by default.

that's something Erel should answer, he wrote or ported that library.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…