n.Initialize
n.Sound = False
n.Vibrate = False
n.SetInfo("goLunch","Baixando imagens",restaurantMenu)
Service.StartForeground(2,n)
Dim query As String
Dim cursor1 As Cursor
Dim baseAddress As String = "https://static-images.test.br/image/upload/pratos/"
Dim targetImage As String
query = "select logoUrl from cadProd where logoUrl is not null"
cursor1 = sql1.ExecQuery(query)
If cursor1.RowCount > 0 Then
Dim job As HttpJob
Dim retImage As Bitmap
Dim out As OutputStream
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
targetImage = cursor1.GetString("logoUrl")
Log("downloading image " & (i + 1) & " de " & cursor1.RowCount)
If targetImage.Trim.Length > 5 Then
If File.Exists(File.DirInternal,targetImage.Replace("/","-") ) = False Then
job.Initialize("",Me)
job.Download(baseAddress & targetImage)
Wait For jobDone(job As HttpJob)
If job.Success Then
retImage = job.GetBitmap
out = File.OpenOutput(File.DirInternal,targetImage.Replace("/","-") ,False)
retImage.WriteToStream(out,100,"JPEG")
out.Close
Else
Log("error downloading image " & job.ErrorMessage)
End If
job.Release
Else
Log("image " & (i+1) & " de " & cursor1.RowCount & " já existe")
End If
End If
Next
End If
Service.StopForeground(2)
Service.StopAutomaticForeground