Book Image

Android Sensor Programming By Example

By : Varun Nagpal
Book Image

Android Sensor Programming By Example

By: Varun Nagpal

Overview of this book

Android phones available in today’s market have a wide variety of powerful and highly precise sensors. Interesting applications can be built with them such as a local weather app using weather sensors, analyzing risky driving behavior using motion sensors, a fitness tracker using step-counter sensors, and so on. Sensors in external devices such as Android Watch, Body Analyzer & Weight Machine, Running Speed Cell, and so on can also be connected and used from your Android app running on your phone. Moving further, this book will provide the skills required to use sensors in your Android applications. It will walk you through all the fundamentals of sensors and will provide a thorough understanding of the Android Sensor Framework. You will also get to learn how to write code for the supportive infrastructure such as background services, scheduled and long running background threads, and databases for saving sensor data. Additionally, you will learn how to connect and use sensors in external devices from your Android app using the Google Fit platform. By the end of the book, you will be well versed in the use of Android sensors and programming to build interactive applications.
Table of Contents (13 chapters)
Android Sensor Programming By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Getting relative humidity from the phone's humidity sensor


Getting values from the phone's relative humidity sensor is a very similar process to getting values from the temperature or pressure sensors. The only difference is in specifying the sensor type. To get the values from the relative humidity sensor, we have to specify the sensor type as TYPE_RELATIVE_HUMIDITY. All the other standard practices  (initiating SensorManager, the Sensor object, and registering and unregistering the listener and the sensor callback) remain the same. Another point to note is that humidity and relative humidity are used interchangeably; they both refer to the same value.

Time for action - calculating the dew point and absolute humidity

We can use the phone's relative humidity and temperature sensor to calculate the dew point and absolute humidity. Before calculating, let's look at the definition and formula of the dew point and absolute humidity.

  • Dew Point: The dew point is the temperature at which a given volume...