Sub DownloadAndViewFile(url As String, mime As String)
Dim sf As String = provider.SharedFolder
Log(sf)
Dim job As HttpJob
job.Initialize("DownloadJob", Me)
job.Username = "Tony" ' Replace with your actual username
job.Password = "TonyTony3" ' Replace with your actual password
job.Download(url)
Wait For (job) JobDone(job As HttpJob)
Log(job.Success)
If job.Success Then
' Save the downloaded file
Dim fname As String = url.SubString(url.LastIndexOf("/")+1)
Log(fname)
Dim out As OutputStream = File.OpenOutput(sf, fname, False)
File.Copy2(job.GetInputStream, out)
out.Close
Log(File.Combine(sf, fname))
Log(File.Size(sf, fname))
Else
Log("Error downloading file: " & job.ErrorMessage)
End If
job. Release
Dim uri As Object = provider.GetFileUri(fname)
Log(uri)
Dim FLAG_GRANT_READ_URI_PERMISSION As Int = 0x00000001
Dim FLAG_ACTIVITY_NO_HISTORY As Int = 0x40000000
Dim i As Intent
i.Initialize(i.ACTION_VIEW, uri)
i.SetType(mime)
i.Flags = Bit.Or(FLAG_GRANT_READ_URI_PERMISSION, FLAG_ACTIVITY_NO_HISTORY)
i.WrapAsIntentChooser("Choose Viewer")
StartActivity(i)
End Sub
Sub Button1_Click
'''DownloadAndViewFile("https://redlightcemetery.com/lara/index.html", "text/html")
DownloadAndViewFile("https://redlightcemetery.com/lara/nevergiveup.jpg", "image/jpeg")
'''DownloadAndViewFile("https://redlightcemetery.com/lara/max7219.pdf", "application/pdf")
End Sub