Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PhoneGap 4 Mobile Application Development Cookbook

You're reading from   PhoneGap 4 Mobile Application Development Cookbook Build real-world hybrid mobile applications using the robust PhoneGap development platform

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783287949
Length 356 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. Welcome to PhoneGap 3 2. Movement and Location – Using the Accelerometer and Geolocation Sensors FREE CHAPTER 3. Filesystems, Storage, and Local Databases 4. Working with Audio, Images, and Video 5. Working with Your Contacts List 6. Hooking into Native Events 7. Working with XUI 8. Working with the Ionic Framework 9. Ionic Framework Development 10. User Interface Development 11. Extending PhoneGap with Plugins 12. Development Tools and Testing Index

Detecting device movement using the accelerometer

The accelerometer captures device motion in the x, y, and z axis direction. The accelerometer is a motion sensor that detects change (delta) in movement relative to the orientation of the current device.

How to do it…

We will use the accelerometer functionality from the plugins to monitor the feedback from the device:

  1. First, create a new PhoneGap project named accelerometer. Open Terminal or Command Prompt and run the following command:
    phonegap create accelerometer com.myapp.accelerometer accelerometer
    
  2. Add the device's 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:
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            &lt...
You have been reading a chapter from
PhoneGap 4 Mobile Application Development Cookbook
Published in: Oct 2015
Publisher:
ISBN-13: 9781783287949
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image