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 – listing the available sensors on a device


There are multiple sensors available on a device. In this section, we will learn how to get a list of all the available sensors. We will be populating the names of the available sensors in a list and will be displaying it on the screen using ListView.

  1. The following code block shows the declarations required by the activity. We don't need the SensorEventListener interface, as we will not be dealing with the values of the sensor. We declare ListView.ListAdapter, and SensorManager, along with the list of Sensor Objects to populate the list:

           public class SensorListActivity extends Activity 
           implements OnItemClickListener{ 
     
             private SensorManager mSensorManager; 
             private ListView mSensorListView; 
             private ListAdapter mListAdapter; 
             private List<Sensor> mSensorsList; 
    
  2. In the onCreate() method, we instantiate our SensorManager, ListView, and ListAdaptor...

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}