Android Code Snippet [B4X] DownloadAndSave

Discussion in 'Code Snippets' started by Erel, Feb 12, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This is a slightly modified sub based on the code from: [B4X] OkHttpUtils2 with Wait For

    Call it when you want to download a file and save it. You can wait for it to complete if needed.
    Sub DownloadAndSave (Url As String, Dir As String, FileName As StringAs ResumableSub
    Dim j As HttpJob
    "", Me)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
    Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
    File.Copy2(j.GetInputStream, out)
    End If
    Return j.Success
    End Sub
    Wait For (DownloadAndSave(URL, File.DirInternal, "map_large.jpg")) Complete (Success As Boolean)
    If Success Then
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice