Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Sensor Programming By Example

You're reading from  Android Sensor Programming By Example

Product type Book
Published in Apr 2016
Publisher Packt
ISBN-13 9781785285509
Pages 194 pages
Edition 1st Edition
Languages
Author (1):
Varun Nagpal Varun Nagpal
Profile icon Varun Nagpal

Table of Contents (13) Chapters

Android Sensor Programming By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Sensor Fundamentals 2. Playing with Sensors 3. The Environmental Sensors – The Weather Utility App 4. The Light and Proximity Sensors 5. The Motion, Position, and Fingerprint Sensors 6. The Step Counter and Detector Sensors – The Pedometer App 7. The Google Fit Platform and APIs – The Fitness Tracker App

Getting air pressure from the phone's pressure sensor


The procedure to get values from the phone's pressure sensor is exactly the same as the previous example showing getting values from temperature sensors. The only difference is the sensor type. To get values from the pressure sensor, we have to specify the sensor type as TYPE_PRESSURE. All other best practices (initiating SensorManager, the Sensor object, and registering and unregistering the listener and sensor callback) remain the same as they were in the previous temperature sensor example.

Time for action – calculating the altitude using the pressure sensor

Once we have atmospheric pressure from the phone's pressure sensor, we can calculate the altitude of the phone using the getAltitude(float p0, float p1) method of the SensorManager class. The first parameter of the altitude API is the atmospheric pressure at sea level, and the second parameter is the atmospheric pressure of the current location, which can be obtained from the phone...

lock icon The rest of the chapter is locked
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 ₹800/month. Cancel anytime}