Android Question HttpUtils2 if file not exist

appie21

Active Member
Licensed User
Longtime User
Hi I have a program to load slideshow images pickedup from my server

The images add by a number

I use a timer for it So that i everytime get a new image (the images are numers 01.jpg, 02.jpg.

job3.Initialize("Job3", Me)
job3.Download("http://mysitei/" & nummer & ".JPG")
It works fin! But how canI set the nummer to 0 agin if the latest file not exist?

For example 10.JPGis not on my server then the count number must be 0

Also if the if image is not avalable i get a succes!

B4X:
Sub JobDone (Job As HttpJob)
  Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
  If Job.Success = True Then
      Select Job.JobName
        Case "Job1", "Job2"
            'print the result to the logs
            Log(Job.GetString)
        Case "Job3"
            'show the downloaded image
            Activity.SetBackgroundImage(Job.GetBitmap)
      End Select
  Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
  Job.Release
End Sub
Sub tijd_Tick
nummer =  "0" & (nummer + 1)
Log (nummer)
job3.Initialize("Job3", Me)
  job3.Download("http://appie21.com/adri/" & nummer & ".JPG")
End Sub

So what do i wrong?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
When you're trying to download a non existent file, I guess you should receive a null object, without an error. So checking for null, would do it. Just a guess.
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Hi i found my problem

If the file not found it go redirect to my mainpage (a errorpage)

But now i have the following problem

If my program is running and i add files to the server (for example i add a image with the order number 6.jpg
the program do dot load that number) the program loop to 5.jpg)

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

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
Dim job1, job2, job3 As HttpJob
Dim tijd As Timer
Dim nummer As Int = 0
End Sub

Sub Activity_Create(FirstTime As Boolean)
  tijd.Initialize("tijd",10000)


  tijd.Enabled = True

  job1.Initialize("Job1", Me)
  'Send a GET request
  'Send a POST request
  job2.Initialize("Job2", Me)


End Sub

Sub JobDone (Job As HttpJob)
  Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
  If Job.Success = True Then
      Select Job.JobName
        Case "Job1", "Job2"
            'print the result to the logs
            Log(Job.GetString)
        Case "Job3"
            'show the downloaded image
            Dim s As String
            s = Job.GetString
       
            If s.Contains ("Welkom") Then
            nummer = 0
            Log("not good")
            Else
            Log ("good")
          Activity.SetBackgroundImage(Job.GetBitmap)
            End If
       
      End Select
  Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
  Job.Release
End Sub
Sub tijd_Tick
nummer = nummer + 1



Log (nummer)
job3.Initialize("Job3", Me)
job3.Download("http://appie21.com/adri/Erik/" & nummer & ".jpg")
' job3.Download("http://appie21.com/adri/Erik/1.jpg")
End Sub
it looks my program not refress when i add files to the server.. what do i wrong?
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Howcan I redim?


the strange is that
i have aserver with pictures 1.jpg and 2.jpg and so on
If I upload a new image (3.jpg) or replace the image on the server my programdid not show it also after a clean install of the apk again the new images on the server not shown?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
What is the timer's real puprose? I would go for downloading all images first, then iterate using a timer, to show them, if this is the purpose.
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Hello
I have a strange thing

I load a image with a button press

job3.Download("http://appie21.com/adri/Erik/1/1.jpg")

it show good

but if i stay in my program and upload a image and replace 1.jpg on the server with a nother image ,and press the button again it won't load the new image (in internet it show the new image correct)
Also if i close my program and reopen and press the button it will not show te new image? but load the old image.

What do I wrong?

I have also
B4X:
Dim links As Map
  links.Initialize
  links.Put(ImageView1, "http://appie21.com/adri/Erik/1/1.jpg")
try


how to refrech inrealtime ?
 
Last edited:
Upvote 0
Top