Back

CreateDownloader

Hello World
Content:
- Methods

The Downloader component can be used to download a file straight from the internet to your phone or tablet's local storage.

dwn = app.CreateDownloader( options ) → app object: Downloader

You can download a file with the Download method which accepts a source url and a target directory: dwn.Download( srcFileUrl, targetDir );

Once the Download method has been called, it show a progress bar with the current download progress. But you can disable this behavior with the “NoDialog” option.

If you want to know when the download process has finished (or failed) you can define a callback functioni with the SetOnComplete method: dload.SetOnComplete( callback );

Example - Example

function OnStart()
{
    var srcFileUrl = "http://sgarman.net/downloadable.txt";
    var targetDir = "/sdcard";

    dload = app.CreateDownloader();
    dload.SetOnComplete( dload_OnComplete );
    dload.Download( srcFileUrl, targetDir );

}

function dload_OnComplete()
{
    app.ShowPopup("Download complete");
}
    Copy     Copy All       Run      

Methods

The following methods are available on the Downloader object:

GetProgress() → Number: fraction (0..1)
GetSize() → Number: bytes
GetType() → String: “Downloader”
IsComplete() → Boolean
Method( name, types, p1, p2, p3, p4 ) → all types
String
String: comma “,” separated: “NoDialog” or “Light”
String: path to file or folder ( “/absolute/...” or “relative/...” ): “must not have a trailing slash”
String: url path
List: [urls]
Object: { COMMAND }
List: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
function( file )
function()
function( path )
function( error )
dwn.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
dwn.Download
Start downloading one or multiple files.
dwn.GetProgress
Returns the current download progress.
dwn.GetSize
Returns the target download size in bytes.
dwn.GetType
Returns the control class name.
dwn.IsComplete
Checks if all downloads are completed.
dwn.Method
Allows access to other functions defined on the object in Java via reflection.

Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
dwn.SetOnCancel
Define a callback function which is called when download is cancelled.
dwn.SetOnComplete
Define a callback function which is called when all downloads are finished.
dwn.SetOnDownload
Define a callback function which is called when a file is download.
dwn.SetOnError
Define a callback function which is called when an error occurred while downloading a file.