Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Adjusting the accelerometer sensor update interval


The getCurrentAcceleration method obtains data from the accelerometer at the time it was called - a single call to obtain a single response object. In this recipe, we'll build an application that allows us to set an interval to obtain a constant update from the accelerometer to detect continual movement from the device.

How to do it…

We will provide additional parameters to a new method available through the PhoneGap API to set the update interval:

  1. First, create a new PhoneGap project named accelupdate. Open Terminal or Command Prompt and run the following command:

    phonegap create accelupdate com.myapp.accelupdate accelupate
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:

    cordova platform add ios
    cordova platform add android
    
  3. Add the device-motion plugin by running the following command:

    phonegap plugin add org.apache.cordova.device-motion
    
  4. Open www/index.html and clean up unnecessary elements; so you have the following...