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 – accessing the device camera


Get ready to access the device's camera and show the user the captured picture. Refer to the following steps:

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

    $ cordova create camera
    
  2. Change to the directory that is created:

    $ cd camera
    
  3. Using the command-line tool, add the Android and iOS platforms to the project:

    $ cordova platforms add android
    $ cordova platforms add ios
    
  4. Add the Camera API plugin using the following command line:

    $ cordova plugin add cordova-plugin-camera
    
  5. Go to the www folder, open the index.html file, and replace the contents with the following code; this code is self-explanatory:

    <!DOCTYPE html>
    <html>
      <head>
        <script type=”text/javascript” charset=”utf-8” src=”cordova.js”></script>
        <script type=”text/javascript” charset=”utf-8”>
    
        // Wait for device API libraries to load
        document.addEventListener(“deviceready”, onDeviceReady,false);
    
        // device...