Queued Downloading to File with Finish Event

Stepdragon

Member
Licensed User
Longtime User
Does anyone have a code snippet that would make it simple to download a url to a specific file, asyncronously, while auto handling queueing. While throwing an event on the main activity and letting it know which file is done downloading?

Basically, is there any way to do this:

B4X:
If File.Exists(SaveFileName) = False then
   Something.DownloadFile(FileURL, File.DefaultRootExternal, SaveFileName)
   Activity.Background = LoadBitmap(File.DirAssets, "Placeholder.png")
Else
   Activity.Background = LoadBitmap(File.DefaultRootExternal, SaveFileName)
End If

Sub Download_finish(Filename as String)
   Activity.Background = LoadBitmap(File.DefaultRootExternal, Filename)
end sub

I want to do something like this so that I can just call the download sub whenever I need to download a file, without having to worry if the previous download has been completed. It would also simplify the need to track which files are currently downloading.

I've seen examples very simmilar to this, but they never let me specify the download directory or filename, and the callback was a general 'Hey, I'm done!', not 'Hey, testimage.png is ready to load... gimme a minute to get the other two done'.

Any Suggestions?
 

Stepdragon

Member
Licensed User
Longtime User
How do I specify what folder and filename to download to? In the examples I've looked at, it seems to only download to the cache folder, and only with the default name. I don't know how to either track what file it is (to move it after download), or how to download directly to the destination folder.

Any Ideas in that regard?
 
Upvote 0

Stepdragon

Member
Licensed User
Longtime User
I've been up and down the HTTPutils over and over, and I still can't figure out any way to choose WHERE TO DOWNLOAD THE FILE!

I have been programming long enough to know that this is a simple thing I'm looking for. All one would need to do is modify the function and callback references. problem is...

I'm new to android development, and to threading in general... as such...
I don't know how to do that.

Can someone throw me a bone here and help me with this? I need a download function where I can specify the URL, and where to save the file, and a callback which tells me which FILE is done, not the URL.

I might want to download "server.com/File386.jpg"
but save it to /mnt/sdcard/files/451.jpg

then during a callback, it does me little to know 'http://server.com/File286.jpg', I would rather my program be told '/mnt/sdcard/files/451.jpg' is done downloading. That way I dont have to do a bunch of arm twisting in the main program to figure out where the finished file actually is.


If you're curious about what I'm working on, its an imageboard app. Basically it reduces the load on the server by downloading each image once, and then only loading it from a file each other time. I save the images based on the Thread and Post IDs rather than the original URL, so it would just add a ton of workaround code if I can't just have a callback with the final filename.
 
Upvote 0
Top