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
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Related Plugin Resources
Index

Time for action – reading and rendering an image


Get ready to render the first available image in the device's storage into the PhoneGap default app template. Refer to the following steps:

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

  2. Add the File API plugin using the following command line:

    $ cordova plugin add cordova-plugin-file
    
  3. Go to the www folder, open the index.html file, and add an img tag with the id value as firstImage inside the main div of the app following the deviceready one:

    <img id='firstImage' />
  4. Go to the www/js folder, open the index.js file, and define a new function named requestFileSystem:

    Function requestFileSystem() {
        // The request of access to the file system will go here
    
    }
  5. Define the error handler in order to get the code of every possible error:

    Function onError(error){
    
         alert(error.code);
    
    }
  6. In the body of the requestFileSystem function, access the device filesystem using the requestFileSystem function of the LocalFileSystem...