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: path to file or folder ( “/absolute/...” or “relative/...” )
string: url path
string: comma “,” separated: “NoDialog” or “Light”
list: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
function( file )
function()
function( path )
function( error )
dwn.Download
Start downloading a file.
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 the download has compleated or not.
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 the download is finished.
dwn.SetOnDownload
Define a callback function which is called when the download is downloaded.
dwn.SetOnError
Define a callback function which is called when an error occurred while downloading the file.