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

Time for action – using the temperature sensor


In this section, we will get the ambient temperature from the phone temperature sensor and will show it in the foreground activity. Before accessing the value for ambient temperature, we will also check the availability of the temperature sensor on the device.

  1. We created a TemperatureActivity and implemented it with the SensorEventListener interface so that it receives the ambient temperature values. We are also checking if the ambient temperature is available on the device and are maintaining the availability state using the isSensorPresent Boolean variable. If the temperature sensor is not present, then we show the relevant message using  TextView. The following code snippet shows the necessary steps:

            public class TemperatureActivity extends Activity 
            implements SensorEventListener{ 
     
              private SensorManager mSensorManager; 
              private Sensor mSensor; 
              private boolean isSensorPresent...
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}