Book Image

PhoneGap Beginners Guide (third edition)

Book Image

PhoneGap Beginners Guide (third edition)

Overview of this book

Table of Contents (22 chapters)
PhoneGap Beginner's Guide Third Edition
About the Authors
About the Reviewers
Related Plugin Resources

Time for action – downloading and saving a file

Get ready to download a file and display in the PhoneGap default app template a progress bar and a link to the file. Refer to the following steps:

  1. Open the command-line tool and create a new PhoneGap project named DownloadFile:

    $ cordova create DownloadFile
  2. Change the directory to DownloadFile:

    $ cd DownloadFile
  3. Add the File and FileTransfer API plugins using the following commands:

    $ cordova plugin add cordova-plugin-file-transfer
    $ cordova plugin add cordova-plugin-file
  4. Go to the www folder, open the index.html file, and add a progress tag with the id value as progress inside the main div element of the app below the deviceready tag; assign 1 to the value attribute and 100 to the max attribute:

    <progress id='progress' value='1' max='100'></progress>
  5. Define a new JavaScript function named onDeviceReady and add it to the deviceready listener:

    document.addEventListener("deviceready", onDeviceReady, false);
       function onDeviceReady...