Android Question B4XGoodies_Check - show progress bar while downloading the huge html file

AnandGupta

Expert
Licensed User
Longtime User
Well, now for the next step I want to add a progress bar showing the download of the huge html file.

Forum search gave me,
https://www.b4x.com/android/forum/threads/download-huge-files-with-httputils2.30220/
https://www.b4x.com/android/forum/threads/downloadmanager.22306/#post129464
https://www.b4x.com/android/forum/t...id-downloadmanager-to-download.59840/#content
etc.

I like to use the Erel's code (#1 above) as it looks simple for my learning phase. But the given sample code did not show any progress both in avd and mobile (release mode).
I understand that this is very old code and B4A 9.5 may have better built in feature for it.
So, how I can fix this code to use in B4XGoodies_Check app ?

Regards,

Anand
 

Attachments

  • B4XGoodies_Check.zip
    73.1 KB · Views: 237

DonManfred

Expert
Licensed User
Longtime User
basically it is this code in the starter service plus one line in the downloadbutton event
B4X:
Sub DLManager_DownloadFinished(downloadid As Long)
    Log($"DLManager_DownloadFinished(${downloadid})"$)
    Dim uri As String = dlman.getUriForDownloadedFile(downloadid)
    Log("Uri = "&uri)
End Sub
public Sub CreateDownloadrequest()
    dlman.Initialize("DLManager")
    dlid = dlman.enqueue(dlman.CreateDownloadRequest("https://www.dropbox.com/s/31w3ksayw80n6b8/b4xgoodies.html?dl=1","Downloading goodies","...",SourceFolder,"b4xgoodies.html",False,True,False))
    Log($"DownloadID = ${dlid}"$)
End Sub

It is using the android downloadmanager service to download the File.

Hope it helps.

Edit to add
If you want to load the html file into a string you can do it like this
B4X:
    Dim cText As String = File.ReadString("ContentDir", uri)
    cText = cText.Replace("<table border=1>", "<table border=1 bgcolor=F0FFFF>")
    Log(cText)
 

Attachments

  • DownloadManagerV0.01.zip
    3.3 KB · Views: 248
  • B4XGoodies_Check.zip
    73.6 KB · Views: 198
Last edited:
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
I checked both the implementations. Thanks Don for updating my code and thanks Erel for fixing the example code.

Don's library show the download in notification but it does not have sub/function to show progress in the app itself, as I understand by studying the codes.
Erel's updated code works as described and it has 'cancel' option along with progress bar in the app itself.

So I have decided to implement Erel's logic as of now in B4XGoodies Check. Will update the same and upload very soon. These few weeks are very busy for me now.

Regards,

Anand
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but it does not have sub/function to show progress in the app itself, as I understand by studying the codes
no, the progress is inside the notification which cames from the Downloadmanager. The Android downloadmanager does not show any UI elements in your app.
But it raises an event when finished.

It is up to you to use it or not ;-)
 
Last edited:
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
no, the progress is inside the notification which cames from the Downloadmanager. The Android downloadmanager does not show any UI elements in your app.
Yes, I saw it and I mentioned that "not in the app itself"

It is up to you to use it or not ;-)
Come on. Is there any one who will not like to use Don's creation :)
Yes I will use it when I want something in the background while user continues working in my app. Thanks for your help.

Regards,

Anand
 
Upvote 0
Top