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 – accessing the Device API

You already used the deviceready event in Chapter 2, Building Your First PhoneGap Project, to handle the bootstrap of our app. Use the device API to get information about the type of device you are running once the event is fired.

  1. Open the command-line tool and create a new Cordova project using the Cordova command-line utility you installed before:

    $ cordova create DeviceApi

    This will create a new directory called DeviceApi in your current working directory.

  2. Move to the directory you just created:

    $ cd DeviceAPI
  3. Add the platforms you want to test on the device API. For example, we add the Android platform:

    $ cordova platform add android
  4. Install the device API plugin. You can also use the shortest way to install the plugin, as shown here, instead of using the entire GIT repository URL:

    $ cordova plugin add cordova-plugin-device
  5. In the www folder inside the project folder you just created, open the index.html file and add a div element with id to render...