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.
- 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. - Move to the directory you just created:
$ cd DeviceAPI
- Add the platforms you want to test on the device API. For example, we add the Android platform:
$ cordova platform add android
- 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
- In the
www
folder inside the project folder you just created, open theindex.html
file and add adiv
element withid
...