Android Question Can I download files from Url and store it inside the app like its assets folder in runtime?

dipdeb

New Member
I need to download files from internet and store it for future access. I'm able to store it in Environment.DIRECTORY_DCIM but I want to store it inside project assets folder. Is it possible?
can someone show me some code example?
Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
I want to store it inside project assets folder. Is it possible?
No. This is not possible. Files in ASSETS are readonly. They must exist in the Files-folder when compiling the App.

You can store downloaded files in File.DirInternal to further access them.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
can someone show me some code example?
Yes - I can.
B4X:
Private Sub Button1_Click
    Wait For (Download("https://example-files.online-convert.com/document/txt/example.txt")) Complete (Success As Boolean)
    If Success Then
        Label1.Text = sample
        File.WriteString(File.DirInternal, "sample.txt", sample)
        Label2.Text = "File size = " & File.Size(File.DirInternal, "sample.txt") & " bytes"
    Else
        Label2.Text = "Download failed."
    End If
End Sub

Private Sub Download (url As String) As ResumableSub
  Dim j As HttpJob
  j.Initialize("", Me)
  j.Download(url)
  Wait For (j) JobDone (j As HttpJob)
    sample = j.GetString
  j.Release
  Return j.Success
End Sub

I attach the complete project. By the way, I had never downloaded a file from a URL before, but I used the Forum Search and soon found an example.
 

Attachments

  • FileDownload.zip
    9.5 KB · Views: 101
Last edited:
Upvote 0
Top